List of GoF Patterns : Overview
A pattern, as name suggests, denotes a recurring problem in software design and explains its solution in a context. These problem/solution pairs have been applied to the best, time tested solutions that apply to any of such problems irrespective of the field or domain.
Software design pattern deals with how to design classes based on the responsibility, defining their collaborations with other classes. GoF defined 3 categories for the patterns such as Creational, structural and behavioural. Creational patterns deal with who creates the classes and how some of the complicated creation process is encapsulated into certain classes. Structural, as it sounds, deals with class collaborations and associations. Behavioural category is concerned with assigning responsibilities to classes.
Below are the one liners of all the patterns. As i go into details of each pattern, when i explain the DOOP car dealer design (remember? i was referring to DOOP design in my last post), each of these one liners will make more sense.
Creational Patterns -
Abstract Factory : This pattern allows to create family of objects without directly referring to the concrete classes.
Builder : Separate complex process of constructing a product from its representation. Its kind of encapsulating complex creation process and let client need not know about that process.
Factory Method : This is nothing but a method to create certain class instance, but this pattern also lets subclasses override this method to create their flavor of class instance.
Prototype : As name suggests, the class acts as prototype to create other instances of the class. New instances will be constructed or cloned from this prototype.
Singleton : This pattern controls count of instances of a class. Every client request for an instance of the class will be responded with the same instance.
Structural Patterns -
Adapter Pattern : An adapter class acts an adapter (remember socket adapter ??) between 2 parties where their interfaces are incompatible to each other.
Bridge Pattern : Decouples an abstraction from implementation so both can vary independently. Will be more clear when we talk in context of an example.
Composite : Represents part-whole hierarchies and lets client treet a leaf and complex tree uniformly.
Decorator : Add responsibilities to classes at runtime (dynamically), not at compile time.
Flyweight : Use sharing to handle huge number of small objects. Limit creation of the very high number of small objects for performance improvement of the app.
Proxy : acts as proxy for another class and diverts actual calls to the class.
Behavioural Patterns -
Chain of Responsibility - Make client unware of who fulfills the request in the chain of handlers. Avoid coupling between client and ultimate request processor.
Command - exposes an interface various requests and lets client call same interface for different requests.
Interpreter - for given language, defines grammer and an interpreter to interpret that language.
Iterator - as name suggests, provides a way to iterate over collections.
Mediator - acts as mediator between 2 parties and encapsulates how these parties interact.
Memento - lets capture and store objects internal state (without violating encapsulation ofcourse), and let the class come backto that state when required (such as serialization..)
Observer - defines dependency between objects, so that when object's state changes, other objects get notified.
State - a pattern that shows the state changes of an entity.
Strategy - dynamically vary or change the algorithms without modifying the client. examples will follow.
Template method - Defines an interface method and certain template methods in base class. The pattern lets subclasses override the template methods such that the actual interface method implementation changes.
Visitor - visitor lets an operation on an object structure. it allows new operations to be defined on that structure w/o changing old operations.
In coming post, i will directly jump into DOOP car dealer design and apply some of these patterns to the design to see what problems these patterns solve.
1 Comments:
nice information!
I find solution with creation an universal factory.
You will find description and source code there.
Post a Comment
Links to this post:
Create a Link
<< Home