IAMGAMEDEVELOPER - Strategy design pattern is one of the dynamic and well structured patterns for designing game. The reason is because of its simple principle that only involves two types of classes in the process of development. However, there will be an advanced of strategy design pattern which must be more complex than its basic pattern. In addition, choosing strategy design pattern as the design pattern for the code structure of game may eliminate several constraints, such as dependencies, encapsulation, and subclass problem.
As mentioned before, there are two types of classes in the strategy design pattern, they are abstract class and strategy class. Basically, the idea of this design pattern is about superclass and subclass, in this case, abstract class becomes the superclass and the subclass is the strategy class.
As mentioned before, there are two types of classes in the strategy design pattern, they are abstract class and strategy class. Basically, the idea of this design pattern is about superclass and subclass, in this case, abstract class becomes the superclass and the subclass is the strategy class.

Let us state that abstract class as a ‘command’ class. It is because of its role that is similiar to a ‘commando’, to give a command to its underlings for choosing one of the strategies for being implemented. Therefore, that is the basic idea of command class, later in the implementation, the functions that are stated in this class will be called by driver, and any function which is chosen will call one of the strategies in the strategy class as its parameter.
Thus, strategy class will state several strategies in the form of classes with different instances, for example, there are two strategies : retreat and destroy. Then the implementation will be looked like the picture below. Moreover, the function which is stated in each strategy class (in the example : virtual int doStrategy(point, int); ) must be declared as the result or return value in one of the function in the command class.

Reference : Core Techniques and Algorithms in Game Programming - Daniel Sanchez-Crespo Dalmau (Book)
No comments:
Post a Comment