Strategy PatternA Strategy Pattern says that "defines a family of functionality, encapsulate each one, and make them interchangeable". The Strategy Pattern is also known as Policy. Benefits:
Usage:
Strategy Pattern in (Core Java API's) or JSE 7 API's:Strategy Pattern in (Advance Java API's) or JEE 7 API's:UML for Strategy Pattern:Implementation of Strategy Pattern:Step 1: Create a Strategy interface. Step 2: Create a Addition class that will implement Startegy interface. Step 3: Create a Subtraction class that will implement Startegy interface. Step 4: Create a Multiplication class that will implement Startegy interface. Step 5: Create a Context class that will ask from Startegy interface to execute the type of strategy. Step 6: Create a StartegyPatternDemo class. Output: Next TopicTemplate Design Pattern |