Design Patterns
GANG OF FOUR (GOF)
Pattern is a solution to a recurring problem, in a specified context.
We can divide the pattern in to 3 categories.
1)Creational Design Pattern
2)Structural Design Pattern
3)Behavioural Design Pattern
Creational Design Pattern :
These patterns involved in obj instantiation & provide a way to decouple the client from the object, it needs to instantiation
EX: Singleton Pattern, Factory Pattern, Builder Pattern, Prototype Pattern
Structural Design Patterns:
These patterns let you compose classes or objects in to a larger structure.
EX: Adapter Pattern, Facade Pattern, Proxy Pattern, Decorator pattern, composite pattern, Bridge Pattern
Behavioural Pattern :
These patterns concerned with, how the classes & objects interact & distribute responsibilities
EX:Observer, Iterator, Command, State, Strategy Pattern, Template method pattern, Visitor Pattern, Mediator Pattern, Interpretor Pattern
We can also divide the patterns in to 2 categories,
1) Class pattern
2) Object Pattern
Class Pattern : Describe how the relationship between the class are defined via inheritance. Relationship in class patterns are established at compile time
1) Factory Pattern
2) Adopter Pattern
3) Interpreter
4) Template
Object Patterns : Describe relationship between objects. Relationship in object patterns are created at runtime & are more dynamic.
1)Singleton
2)Facade
3)Observer
4)Command
5)Composite
6)Decorator
7)Proxy
8)Iterator
9)Strategy
10)Bridge
11)Prototype
1. Facade Design Pattern
Is the pattern when ever we want to provide simplified interface to client that performs many other actions behind
2. Proxy Design Pattern :
Proxy Design pattern is class which will limit access to another class. This can be used for security reasons.
3. Factory Design Pattern :: When a method returns ond of the several possible classes that share a common super class.
We need to get a capability to choose a class at runtime.
4. Singleton pattern helps us to keep only one instance of a class at any time. The purpose of singleton is to control object creation by keeping private constructor.
Example like java.lang.Runtime, java.awt.Desktop are built in singleton classes and in case of logging, configuration file, cache