- Adapter: The Adapter pattern is used to adapt one interface to another, allowing classes to work together that couldn't otherwise because of incompatible interfaces.
Why? The purpose of the Adapter pattern is to allow two classes with incompatible interfaces to work together by adapting one interface to match the other.
And what is the practical purpose of that? By using the Adapter pattern, you can reuse existing code or libraries that have incompatible interfaces, without having to modify the code of the existing classes. This can be useful in situations where you want to use an existing library or codebase, but the interface doesn't match the requirements of your system.
- Facade: The Facade pattern is used to provide a simplified interface to a complex system, hiding the complexity behind a single, unified interface.
Why? The purpose of the Facade pattern is to provide a simple, easy-to-use interface to a complex system, by hiding the complexity of the system behind a single, unified interface.
And what is the practical purpose of that? By using the Facade pattern, you can make it easier for users of a complex system to understand and use the system, without having to understand the underlying complexity. This can be useful in situations where you want to provide a simple, user-friendly interface to a complex system, or where you want to hide the complexity of the system from users.
- Bridge: The Bridge pattern is used to separate an abstraction from its implementation, allowing the two to vary independently.
Why? The purpose of the Bridge pattern is to decouple an abstraction from its implementation, so that the two can vary independently.
And what is the practical purpose of that? By using the Bridge pattern, you can change the implementation of an abstraction without affecting the abstraction itself, or the code that uses the abstraction. This can be useful in situations where you want to be able to change the implementation of an abstraction without affecting the code that uses the abstraction.
- Decorator: The Decorator pattern is used to dynamically add behavior to an object, by wrapping it in an additional object.
Why? The purpose of the Decorator pattern is to add behavior to an object dynamically, by wrapping the object in an additional object.
And what is the practical purpose of that? By using the Decorator pattern, you can add new behavior to an object without changing the object's code, or without creating a new subclass. This can be useful in situations where you want to add behavior to an object without modifying the object's code, or where you want to add behavior to multiple objects in a flexible way.
- Composite: The Composite pattern is used to compose objects into tree structures to represent part-whole hierarchies.
Why? The purpose of the Composite pattern is to allow you to treat individual objects and compositions of objects uniformly.