Design Patterns
A design pattern is intended to give general solutions to reoccuring design problems in programming. The naming of these patterns can provide a shared design language between developers. They are often associated with object-oriented programming, although all patterns can be implemented in any non-OOP languages in principle.
The most basic types of design patterns are
- Structural Patterns
- Creational Patterns
- Behavioural Patterns
Structural Patterns
These design patterns are about organizing different classes and objects to form larger structures and provide new functionality.
Structural design patterns are:
- Adapter: Converts the interface of a class into another interface clients expect. Let's classes work together that couldn't otherwise because of incompatible interfaces. There are Class Adapters & Object Adapters.
- Bridge
- Composite: Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
- Decorator: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
- Facade: Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
- Flyweight
- Private Class Data
- Proxy: Provide a surrogate or placeholder for another object to control access to it.
Creational Patterns
These design patterns are all about class instantiation or object creation. These patterns can be further categorized into class-creational patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.
Creational design patterns are…
- Factory Method
- Abstract Factory
- Builder
- Singleton: Ensure a class only has one instance and provide a global point of access to it.
- Object Pool
- Prototype
Behavioural Patterns
Behavioural patterns are about identifying common communication patterns between objects and realize these patterns.
Behavioral patterns are…
- Chain of responsibility
- Command: Encapsulates a request as an object, thereby letting you parameterize clients with different request, queue or log requests, and support undoable operations.
- Interpreter
- Iterator: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
- Mediator
- Memento
- Null Object: A null object is useful when you don't have a meaningful object to return, and yet want to remove the responsibility for handling null from the client. For Instance, in our remote control we didn't have a meaningful object to assign to each slot out of the box, so we provided a NoCommand object that acts as a surrogate and does nothing when its execute method is called.
- Observer
- State: Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class.
- Strategy: defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
- Template Method: Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.
- Visitor
Resources
- Head First Design Patterns - A Brain-Friendly Guide
- Game Programming Patterns