Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualAllEightUp

Posted 10 September 2013 - 09:15 PM

Beyond the code in general, I suspect there is a disconnect in the intention of the strategy pattern here as I mentioned in our chat. What are you changing based on the "strategy" here? The only things being changed are two member values, that is simple C++ initialization pattern and not something you use the "strategy" pattern for.

While there is nothing wrong with your implementation after the fixes, there is still a fundamental issue that this is not the intention of the strategy pattern as described by the GOF design patterns book. Given this code, you have implemented a single strategy: "GroundMovement", the changes in values don't change the strategy and are simply initialization values. To make this an actual strategy, you might add "AirMovement" which calculates gravity effect on the movement algorithm, so the actual code for "moveXUnits" changes between the strategies. The intention of the strategies is to insert new code to change the fundamental behavior of certain common calls, not to simply change some values here and there because that is covered in the non-book design pattern of simple C++.

Hopefully this is helpful. I'm not trying to be an ass, but using patterns means using them for the correct reasons, without that proper application you are writing overly complicated code for no good reason but calling it a pattern not intended for this problem. This leads to confusion and poor code in the long run I'm sorry to say..

#1AllEightUp

Posted 10 September 2013 - 09:08 PM

Beyond the code in general, I suspect there is a disconnect in the intention of the strategy pattern here as I mentioned in our chat. What are you changing based on the "strategy" here? The only things being changed are two member values, that is simple C++ initialization pattern and not something you use the "strategy" pattern for.

While there is nothing wrong with your implementation after the fixes, there is still a fundamental issue that this is not the intention of the strategy pattern as described by the GOF design patterns book. Given this code, you have implemented a single strategy: "GroundMovement", the changes in values don't change the strategy and are simply initialization values. To make this an actual strategy, you might add "AirMovement" which calculates gravity effect on the movement algorithm, so the actual code for "moveXUnits" changes between the strategies. The intention of the strategies is to insert new code to deal with common code elements, not to simply change some values here and there because that is covered in the non-book design pattern of simple C++.

Hopefully this is helpful. I'm not trying to be an ass, but using patterns means using them for the correct reasons, without that proper application you are writing overly complicated code for no good reason but calling it a pattern not intended for this problem. This leads to confusion and poor code in the long run I'm sorry to say..

PARTNERS