Exploring behavioral design patterns
As the name suggests, behavioral design patterns deal with the behavior of objects and how they talk to each other. In this section, we will learn about the elements of the chain of responsibility, command, and strategy design patterns, which belong to the behavioral design pattern category, and understand them by applying them to ABC Megamart.
Understanding the chain of responsibility
The chain of responsibility is a design pattern where the responsibility of the actions that can be performed by objects are transferred from one object to another, similar to a chain of events or actions. To explain this further and to implement this design pattern, we need the following elements to be developed in our code:
- Parent handler: A base class that defines a base function that specifies how a sequence of actions should be handled.
- Child handlers: One or more subclasses that overwrite the base function from the base class to perform the...