Strategy Pattern

The Strategy pattern is a behavioral pattern that allows you to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. The pattern allows you to vary the behavior of an object by selecting the appropriate algorithm at runtime. The main idea behind the Strategy pattern is to provide a way to change an object’s behavior without changing its implementation. Instead of implementing a single algorithm directly in the object, the Strategy pattern defines a set of algorithms as separate objects and allows the object to select the appropriate algorithm at runtime....

May 20, 2023 · aaron

State Pattern

The State pattern is a behavioral pattern that allows an object to alter its behavior when its internal state changes. The pattern encapsulates state-dependent behavior into separate classes, and the object’s behavior changes at runtime by switching between different state objects. The main idea behind the State pattern is to provide a way to change an object’s behavior without changing its class. Instead of using conditional statements to determine the behavior of an object based on its state, the State pattern uses a set of state classes that encapsulate the behavior and a context object that delegates to the current state....

May 20, 2023 · aaron

Observer Pattern

The Observer pattern is a behavioral pattern that defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. The main idea behind the Observer pattern is to provide a way for objects to be notified of changes in the state of another object without tightly coupling them together. This allows for a more flexible and maintainable design by separating the concerns of the objects....

May 20, 2023 · aaron

Memento Pattern

The Memento pattern is a behavioral pattern that allows you to capture and externalize an object’s internal state so that the object can be restored to that state later without violating encapsulation. The main idea behind the Memento pattern is to provide a way to save and restore an object’s state without exposing its internal structure. This allows you to save the state of an object at a particular point in time and restore it later if necessary....

May 20, 2023 · aaron

Mediator Pattern

The Mediator pattern is a behavioral pattern that defines an object that encapsulates how a set of objects interact with each other. It promotes loose coupling by keeping objects from referring to each other explicitly and allows for their interaction to be centralised in a mediator object. The main idea behind the Mediator pattern is to reduce the complexity of the interactions between objects by introducing a mediator object that handles the communication between them....

May 20, 2023 · aaron