Factory method - defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
Abstract factory - provides an interface for creating families of related or dependent objects without specifying their concrete classes.
Decorator - attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Adapter - converts the interface of a class into another interface the client expect. Adapter lets classes work together that coun't otherwise because of incompatible interfaces. Object adateprs and class adapters (composition vs ingeritance). Here is the Object Adapter UML:
Facade - provide a unified interface to a set of interfaces in a subsytem. Facade defines a higher-level interface that makes the subsystem easier to use. Object adateprs and class adapters (composition vs ingeritance). Here is the Object Adapter UML:
The Principle of Least Knowledge talk only to your immediate friends.
Composite - compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Strategy - defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
State - allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Observer - defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Command - encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Template method - defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
Iterator - provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
- Decorator
- Factory Method
- Abstract Factory
- Command
- Adapter
- State
- Strategy
- Observer
- Decorator
- Factory Method
- Abstract Factory
- Command
- Adapter
- State
- Encapsulate what varies
- Favor composition over inheritence
- Program to interfaces, not implementations
- Strive for loosely coupled designs between objects that interact
- Classes should be open for extension but closed for modification
- Depend on abstractions. Do not depend on concrete classes
- Only talk to your friends (The Principle of Least Knowledge)
- Don't call us, we'll call you (Hollywood Principle)
- A class should have only one reason to change