60 likes | 148 Views
Strategy Design Pattern. B.Ramamurthy. Strategy. Often there are alternative ways or strategies to achieve a goal. These strategies are usually realized using algorithms. Only one of them may be used depending on the context .
E N D
Strategy Design Pattern B.Ramamurthy B.Ramamurthy
Strategy • Often there are alternative ways or strategies to achieve a goal. • These strategies are usually realized using algorithms. • Only one of them may be used depending on the context. • The algorithms representing the strategies can be encapsulated each in a class. • Strategy pattern itself represents a collection of these alternative ways in a hierarchy of classes, each class representing an alternative. B.Ramamurthy
Strategy Design B.Ramamurthy
Examples • Different layouts for graphical components (JFrame, JPanel, JApplet) • Checkout counter software has TaxCalculator class. Depending on the place (context) the tax computation differs. • Mr.X’s strategies in the ScotlandYard game. B.Ramamurthy
Mr.X and Strategy Design Pattern B.Ramamurthy
Layout Example B.Ramamurthy