Sunday, May 10, 2009
What are different types of Design Patterns
Design patterns are mainly of three different types
1. Creational Patterns: Helps you in creation of objects rather then you instantiating objects directly.
2. Structural Patterns : Helps you to compose or build groups of objects into larger structures, such as complex user interfaces or accounting data
3. Behavioral Patterns: Helps you in establishing communication between objects.
When to use Design Patterns?
Of course we should think of design patterns while designing the application, but the question is what pattern to use when.
Creational design patterns:
When your design needs to create objects in the system you should think of creational patterns. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.
Some examples of creational design patterns include:
Abstract factory pattern: centralize decision of what factory to instantiate
Factory method pattern: centralize creation of an object of a specific type choosing one of several implementations
Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations
Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed
Object pool: avoid expensive acquisition and release of resources by recycling objects that are no longer in use
Prototype pattern: used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects
Singleton pattern: restrict instantiation of a class to one object
Structural Patterns: When you design complex objects on top of the existing objects you can think of any of the structural patterns.
Some of the examples of Structural Pattern include
• Adapter pattern: 'adapts' one interface for a class into one that a client expects
• Aggregate pattern: a version of the Composite pattern with methods for aggregation of children
• Bridge pattern: decouple an abstraction from its implementation so that the two can vary independently
• Composite pattern: a tree structure of objects where every object has the same interface
• Decorator pattern: add additional functionality to a class at runtime where subclassing would result in an
exponential rise of new classes
• Extensibility pattern: aka. Framework - hide complex code behind a simple interface
• Facade pattern: create a simplified interface of an existing interface to ease usage for common tasks
• Flyweight pattern: a high quantity of objects share a common properties object to save space
• Proxy pattern: a class functioning as an interface to another thing
• Pipes and filters: a chain of processes where the output of each process is the input of the next
• Private class data pattern: restrict accessor /mutator access
Behavioral Patterns: Behavioral patterns define the communication patterns between objects. These objects
Examples of this type of design pattern include:
Chain of responsibility pattern: Command objects are handled or passed on to other objects by logic-containing processing objects
Command pattern: Command objects encapsulate an action and its parameters
Interpreter pattern: Implement a specialized computer language to rapidly solve a specific set of problems
Iterator pattern: Iterators are used to access the elements of an aggregate object sequentially without exposing its underlying representation
Mediator pattern: Provides a unified interface to a set of interfaces in a subsystem
Memento pattern: Provides the ability to restore an object to its previous state (rollback)
Null Object pattern: designed to act as a default value of an object
Observer pattern: aka Publish/Subscribe or Event Listener. Objects register to observe an event which may be raised by another object
State pattern: A clean way for an object to partially change its type at runtime
Strategy pattern: Algorithms can be selected on the fly
Specification pattern: Recombinable Business logic in a boolean fashion
Template method pattern: Describes the program skeleton of a program
Visitor pattern: A way to separate an algorithm from an object
Single-serving visitor pattern: Optimize the implementation of a visitor that is allocated, used only once, and then deleted
Hierarchical visitor pattern: Provide a way to visit every node in a hierarchical data structure such as a tree.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment