Wednesday, 25 February 2015

Different types of Design patterns and the differences between them

Different types of Design patterns and the differences between them:

Design patterns divided into three groups.

Now let us see about each one, and where exactly these are useful:

Creational Design pattern:

These patterns are useful when we want to create the object of the particular class that is the solution for our problem.  I .e when we try to take the decision of the class that we want to access at the run time instead of the compile time.

Creational patterns support the creation of objects in a system. Creational patterns allow objects to be created in a system without having to identify a specific class type in the code, so you do not have to write large, complex code to instantiate an object.

 It does this by having the subclass of the class create the objects. However, this can limit the type or number of objects that can be created within a system.


1. Abstract factory pattern: which provides an interface for creating related or dependent objects without specifying the objects' concrete classes.

2. Builder pattern:  which separates the construction of a complex object from its representation so that the same construction process can create different representation.

3. Factory method pattern: which allows a class to defer instantiation to subclasses.

4. Prototype pattern: which specifies the kind of object to create using a prototypical instance, and creates new objects by cloning this prototype.

5. Singleton pattern: which ensures that a class only has one instance, and provides a global point of access to it.


Behavioral Design Pattern:

This type of patterns describes how objects are communicated with each other. Using this type of design patterns, we can reduce the complexity of the flow chart to show the interconnection between the objects of different classes.

It will show how the objects communicated with each other.
Behavioral class patterns use inheritance to distribute behavior between classes.

 The Template Method is the simpler and more common of the two. A template method is an abstract definition of an algorithm. It defines the algorithm step by step. Each step invokes either an abstract operation or a primitive operation. A subclass fleshes out the algorithm by defining the abstract operations.
List of design patters that comes under the Behavioral design pattern are:
1. Command: Objects encapsulate an action and its parameters

2. Interpreter: This implement a specialized computer language to rapidly solve a specific set of problems

3. Chain of responsibility: The objects that are handled on to the other objects by logic-containing processing objects

4. Iterator: This Iterators Patterns are used to access the elements of an aggregate object sequentially without exposing its underlying representation

5. Mediator: Provides a unified interface to a set of interfaces in a subsystem

6. State: A clean way for an object to partially change its type at runtime

7. Strategy: Algorithms can be selected on the fly

8. Template Method: Describes the program skeleton of a program

9. Visitor: A way to separate an algorithm from an object

10. Memento: Provides the ability to restore an object to its previous state (rollback)

11. Observer: also known as Publish/Subscribe or Event Listener. Objects register to observe an event that may be raised by another object



Structural Design Pattern:

Structural patterns form larger structures from individual parts, generally of different classes.
Structural patterns vary a great deal depending on what sort of structure is being created for what purpose.

Structural patterns are concerned with how classes and objects are composed to form larger structures.

1. Adapter: Adapts one interface for a class into one that a client expects.

2. Bridge: Decouple an abstraction from its implementation so that the two can vary independently

3. Flyweight: A high quantity of objects share a common properties object to save space

4. Proxy: A class functioning as an interface to another thing

5. Composite: A tree structure of objects where every object has the same interface

6. Decorator : Add additional functionality to a class at runtime where subclassing would result in an exponential rise of new classes

7. Facade: Create a simplified interface of an existing interface to ease usage for common tasks


No comments: