State PatternA State Pattern says that "the class behavior changes based on its state". In State Pattern, we create objects which represent various states and a context object whose behavior varies as its state object changes. The State Pattern is also known as Objects for States. Benefits:
Usage:
UML for State Pattern:Implementation of State Pattern:Step 1: Create a Connection interface that will provide the connection to the Controller class. Step 2: Create an Accounting class that will implement to the Connection interface. Step 3: Create a Sales class that will implement to the Connection interface. Step 4: Create a Sales class that will implement to the Connection interface. Step 5: Create a Management class that will implement to the Connection interface. Step 6: Create a Controller class that will use the Connection interface for connecting with different types of connection. Step 7: Create a StatePatternDemo class. Output: Next TopicStrategy Design Pattern |