Singleton Pattern | Ensures that a class has only one instance and provides a global point of access to that instance. | Used in logging systems, database connections, and configuration settings. |
Factory Method Pattern | Defines an interface for creating an object but allows subclasses to alter the type of objects created. | Frameworks where the classes defining the objects are not known in advance or are dynamically loaded. |
Abstract Factory Pattern | Provides an interface for creating families of related or dependent objects without specifying their concrete classes. | GUI libraries where different GUI components need to be created based on the operating system or platform. |
Observer Pattern | Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. | Event handling mechanisms in graphical user interfaces, such as notifying multiple UI components when a data model changes. |
Decorator Pattern | Attaches additional responsibilities to an object dynamically, providing a flexible alternative to subclassing for extending functionality. | Adding new behaviors to objects at runtime, such as adding borders or scrollbars to a graphical component. |
Adapter Pattern | Allows incompatible interfaces to work together by providing a bridge between them. | Adapting an old interface to a new one, making legacy code compatible with new systems or libraries. |
Strategy Pattern | Defines a family of algorithms, encapsulates each one, and makes them interchangeable. | Sorting algorithms in a sorting application, where different sorting algorithms can be selected and used interchangeably. |
Composite Pattern | Composes objects into tree structures to represent part-whole hierarchies. | GUI frameworks where components can be nested hierarchically, such as in graphical editors. |
Iterator Pattern | Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. | Iterating over elements of a collection without exposing the internal structure of the collection. |
Command Pattern | Encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations. | GUI applications where actions performed by users are encapsulated as objects, allowing for undo/redo functionality and queuing requests. |
Builder Pattern | Separates the construction of a complex object from its representation, allowing the same construction process to create different representations. | Creating complex objects with multiple parameters or optional features, such as constructing a complex query object for a database query. |