Design Patterns in Java
Design Patterns in Java
Design pattern is generally used to solve common software problems. That’s why it is a very renowned for software developers. Here we will discuss about Java design patterns.
There are three types of Design patterns in Java, Creational, Structural, and Behavioural design pattern. Each of the 3 patterns has also some pattern types. Here I have created an index to understand
Creational Design Pattern
- Singleton Pattern
- Factory Pattern
- Abstract Factory Pattern
- Builder Pattern
- Prototype Pattern
Structural Design Pattern
- Adapter Pattern
- Composite Pattern
- Proxy Pattern
- Flyweight Pattern
- Facade Pattern
- Bridge Pattern
- Decorator Pattern
Behaviour Design Pattern
- Template Method
- Pattern Mediator
- Pattern Chain Of Responsibility
- Observer Pattern
- Strategy Pattern
- Command Pattern
- State Pattern
- Visitor Pattern
- Interpreter Pattern
- Iterator Pattern
- Memento Pattern
Creational Design Pattern:
An object represented for an actual example fittest for specific situation is provided by Creational Design Pattern.
Singleton pattern controls objectifying of a class and make sure that only one object exists in the Java virtual machine of that class. It is designed very simple looking but at implementation time many implementation concerns come together to make it difficult. That’s why it is a controversial topic among developers.
When we have super class with various sub-classes and for placed inputs have to go to previous sub-class then Factory design pattern is in use. When it comes to objectifying of a class form client programme to factory class Factory pattern accept its negative consequences and make the process right. Singleton pattern is also applicable on factory class or factory method can be unchangeable.
Abstract Factory Pattern:
Abstract factory pattern is implemented to remove if-else block and to get factory class for every single sub-class. After all this process with base on factory class inputs Abstract factory class returns to sub-class.
To solve some attribute contain Object issues of Factory and Abstract factory design pattern Builder pattern is used. Builder pattern with a vast framework and inconsistent state make a way for step-by-step object building and provides a thorough process in which you can reach the actual final Object. The throughout process will performed by Builder pattern to solve issues.
Prototype pattern is used to reduce time and cost of object creation. In this pattern it copies an existing object to a new object and modify it on basis of needs. Java cloning is used to copy in this pattern.
Structural Design Pattern:
For Class structure creation Structural Design Pattern is used.
This pattern is used to conjugate two un related interface for same work. An adapter is used to join the two interface.
It is a Structural design pattern and represents ladder structured object. Composite design pattern creates a structure in which all objects will get same treatment.
Proxy design pattern creates a single access point to get vast accessibility of object. In this pattern client will get a range of operations with controlled access.
Flyweight design pattern reduces captured memory space by sharing objects either it would be mobile devices or embedded systems. For creating lot of objects in a class this pattern is very much needed.
Facade pattern is used to help client application by creating wrapper interface on top of client interface to make it easy to manage. For interacting client interface with the system this pattern is used for.
Bridge design pattern is used to separate the interfaces of two ladder type objects from implementation and hide from client programmes about there implementation details.
Decorator design pattern modifies object functionality at runtime.This pattern is used to give modified behaviour of a single object in class and also cares other object of the same class would not be affected by its behaviour. It also feats in Structural design category like other pattern. It uses proper classes or interface with the framework at the time of implementation.
Behavioural Design Pattern:
For better interaction between objects, making connection between components in a system and to get a flexible extension the ultimate solution is Behavioural design pattern.
Template Method Pattern:
In this method a code will be created to define some other programmer functionality and postpone the implementation process of some steps to the subclass.
This pattern creates a communication medium in a system for different objects. For enterprise application this pattern is very helpful because the more the objects communicate with each other the merrier the application will be easy to handle.
Pattern Chain of Responsibility:
In this pattern chain of object carried out whole process of the client request. After request sent object will decide that which one is suitable for the process .
This is the pattern where you will be notified about any change of the state of an object in which you interested.
The strategy pattern is used to choose the right algorithm to implement to run a specific task. It is also known as Policy Pattern.
In this process invoker receive the request and send it to the compressed command object . This pattern is a request respond model.
Based on its internal state when an object changes behaviour then State design pattern is used.
When it comes to perform a task on a group of objects with same kind then visitor design pattern is used.
This pattern represents as a grammatical interpreter for the used language.
This design pattern is for travel through a group of objects collection.
This pattern is used to save an object securely, and inaccessible without proper permission.
Benefits of Java Design Pattern:
Java Design Pattern is used to solve industry level problems with less time. It reduces cost of software product of owner because its codes are reusable.