There are three types of GoF Design patterns: Creational Design Pattern, Structural Design Pattern and Behavioral Design Pattern. GoF: gang of four desgin pattern.
1. Overview of GoF Design Patterns
- Creational Design Pattern : used for creating object in software design pattern.
- Structural Design Pattern : refer for structuring of object(s) in software design pattern.
- Behavioral Design Pattern : used for behavior of objects in software design pattern.
2. GoF: Creational Design Pattern
Creational design pattern is one of the GoF desing patterns. You will learn more about creational pattern. Key points are as:
- Deal with one of the most commonly performed tasks in an OO application, the creation of objects.
- Support a uniform, simple, and controlled mechanism to create objects.
- Allow the encapsulation of the details about what classes are instantiated and how these instances are created.
- Encourage the use of interfaces, which reduces coupling.
3. Type of Creational Design Patterns
- Singleton: Provides a controlled object creation mechanism to ensure that only one instance of a given class exists.
- Prototype: Provides a simpler way of creating an object by cloning it from an existing (prototype) object.
- Factory Method: Subclass decides which concrete class to instantiate. When a client object does not know which class to instantiate , it can make use of the factory method to create an instance of an appropriate class from a class hierarchy or a family of related classes.
- Abstract Factory: Allows the creation of an instance of a class from a suite of related classes without having a client object to specify the actual concrete class to be instantiated.
- Builder: Allows creation of a complex object by providing the information on only its type and content, keeping the details of the object creation transparent to the client. This allows the same construction process to produce different representations of the object.
4. Structural Design Pattern
Structural design patterns is one of the GoF design patterns. Following are the structural design pattern with high level one liner things about this.
- Adapter : adapt the object behaviors
- Composite: allows you to compose object into tree structures to represent part-whole hierarchies. client treats composite object and individual object uniformly.
- Facade: Make interface simpler
- Flyweight: make object light weight by reducing
- Proxy: hiding implantation from client
5. Behavioral Design Patterns
- Chain Of Responsibility:
- Proxy: provides a surrogate or placeholder for another object to control access to it.
- Iterator: Provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
- Strategy: Encapsulate interchangeable behaviors and use delegation to decide which behavior to use.
- Template Method: Subclass decides how to implement step in an algorithm.
6. Patterns in Java Collection
Collectional pattern primarily deal with group or collections of Object. It allow the definition of operations on collections of objects, which are follows:
7. One liner about Adaptor Decorator and Facade
- Adapter : Convert one interface to another
- Decorator: Does not alter the interface but add responsibility.
- Facade : Make an interface simpler
8. Strategy Vs Template Method
Template Method job is to define the outline of an algorithm, but subclass do some of the work. It means , I ( Template) have more control over my algorithm and I don’t duplicate code. All the duplicate code put into super class so that all subclass share those code.
Strategy method use object composition while Template use inheritance. Click here Template Method Vs Strategy Design pattern
9. Who wraps object for what?
- Adapter: Wraps another object and provides a different interface to it.
- Decorator: wraps another object and provides additional behavior for it.
- Facade: wraps a bunch of objects to simplify their interface.
- Proxy: wraps another object to control access to it.
I hope you enjoyed this post of behavioral design patterns, and you can visit design patterns tutorial for more details
Visit Wiki page.
Happy learning of GoF design Patterns:)