Creational patterns provide a solution to instantiate an object in the best possible way for specific situations.
Singleton: restricts the instantiation of a class to a singular instance.
Factory Method Pattern: defines an interface or an abstract class for creating the object and lets the subclasses decide which class to instantiate.
Abstract Factory: provides an interface for creating families of related or dependent objects without specifying their concrete classes and implementation
Builder: Encapsulate creating and assembling the parts of a complex object in a separate Builder object. A class delegates object creation to a Builder object instead of creating the objects directly.
Prototype enables the creation of new objects by copying an existing object. Prototype allows us to hide the complexity of making new instances from the client. The existing object acts as a prototype and contains the state of the object.
Structural patterns provide different ways to create a class structure, for example, using inheritance and composition to create a large object from small objects.
Adapter: enables the usage of an existing class's interface as an additional interface.
Composite: lets you compose objects into tree structures and then work with these structures as if they were individual objects.
Proxy: is a class functioning as an interface to something else. In short, a proxy is a wrapper or agent object that is called by the client to access the real serving object behind the scenes.
Flyweight tries to reuse already existing similar kinds of objects by storing them, and creates a new object when no matching object is found. We will demonstrate this pattern by drawing 20 circles in different locations, but we will create only 5 objects.
Facade adds an interface to an existing system to hide its complexities.
Bridge decouples the implementation class and the abstract class by providing a bridge structure between them.
Decorator acts as a wrapper to an existing class.
Behavioral patterns provide a solution for better interaction between objects and how to provide loose coupling and flexibility to extend easily.
Template Method is a method in a superclass, usually an abstract superclass, that defines the skeleton of an operation in terms of several high-level steps. These steps are themselves implemented by additional helper methods in the same class as the template method.
Mediator communication between objects is encapsulated within a mediator object. Objects no longer communicate directly with each other, but instead communicate through the mediator.
Chain of Responsibility creates a chain of receiver objects for a request. This pattern decouples the sender and receiver of a request based on the type of request.
Observer is used when there is a one-to-many relationship between objects, such as if one object is modified, its dependent objects are to be notified automatically
Strategy a class behavior or its algorithm can be changed at run time.
Command A request is wrapped in an object as a command and passed to the invoker object. Invoker object looks for the appropriate object that can handle this command and passes the command to the corresponding object, which executes the command.
State that allows an object to alter its behavior when its internal state changes.
Visitor separates the algorithm from the object structure. Because of this separation, new operations can be added to existing object structures without modifying the structures. It is one way to follow the open/closed principle in object-oriented programming and software engineering.
Interpreter provides a way to evaluate language grammar or expression.
Iterator is used to traverse a container and access the container's elements.
Memento contains state of an object to be restored. Originator creates and stores states in Memento objects and Caretaker object is responsible to restore object state from Memento.