Table of Contents
Design patterns are general solutions to routine problems in software design. Every pattern acts as a blueprint that allows customization to solve a given design problem in any code during the development of software modules.
A design pattern systematically names, motivates and explains a general design that addresses a recurring design problem in object-oriented systems. Design patterns are needed to represent some of the best practices followed and adopted in software development.
Software Design Pattern can be defined as a software template or a description to solve a problem that occurs in multiple instances while designing a Software Application or a Software Framework.
The credit of Design Patterns goes to the Gang of Four. Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides were the authors of the book on the Java Design Patterns.
Structure of a Design Pattern
Structure of any Design Pattern is considered to be highly organised. They are often documented in the form of a template such that, the users can visually identify the problem and instantaneously find the solution to it, based on the relationship between classes and objects. The Design Patterns Template described by the original authors of the Design Patterns is as follows:
|Pattern Name||Describes the essence of the pattern in a short, but expressive name.|
|Intent||Describes what the Pattern Does|
|Also, known as||List any synonyms of the pattern|
|Motivation||Provides an example of the problem and describes the solution to it|
|Applicability||Lists the situations where the pattern is applicable|
|Structure||Set of diagrams of the classes and objects that depict the pattern|
|Participants||Describes the classes and objects that participate in the design|
|Collaborations||Describes the Participants collaboration and their responsibilities.|
|Consequences||Describes the forces that exist with the pattern and the benefits|
Types of Design Patterns
Java Design Patterns are divided into Four Categories:
- Creational Design Patterns are concerned with the method of creating Objects.
- Structural Design Patterns deal with the composition of classes and objects which form larger structures.
- Behaviour Design Patterns are concerned with the responsibility and interaction between the objects.
- JEE Design Patterns are concerned with providing solutions to the Java EE-based software applications and frameworks.
Creational Design Patterns
They are preferred during the process of class initiation. The Creational Design Patterns are further classified as follows:
- Factory Pattern
- Abstract Factory Pattern
- Singleton Pattern
- Prototype Pattern
- Builder Pattern.
- Object Pool Pattern
Factory Design Pattern: It follows the principle of “Define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate“. The Factory Method Pattern is also known as Virtual Constructor.
- It is designed to allow all the sub-classes to choose the type of objects so as to create them.
Singleton Design Pattern: It follows “define a class that has only one instance and provides a global point of access to it“. The class must ensure that only a single instance should be created and a single object can be used by all other classes.
- It is designed to save memory.
- The object is not created on every request, instead, a single instance is reused.
Structural Design Patterns
It deal with the composition of classes and objects which form larger structures. They simplify the structure by identifying the relationship between the classes and objects. The Structural Design Patterns are further classified as follows:
- Facade Pattern
- Bridge Pattern
- Composite Pattern
- Decorator Pattern
- Adapter Pattern
- Flyweight Pattern
- Proxy Pattern
- Filter Pattern
Facade Design Pattern: Describes a higher-level interface that makes the subsystem easier to use. Every Abstract Factory is a Facade Design Pattern.
- It protects the end-users from the complex sub-system components.
Adapter Design Pattern: Provides the interface according to client requirement while using the services of a class with a different interface. The Adapter Pattern is also known as Wrapper.
- It is designed to enable two or more previously incompatible objects to interact with each other.
Behavioural Design Patterns
They are concerned with the responsibility and interaction between the objects. These Design Patterns make sure the objects are loosely coupled, yet, can easily communicate with each other. Behavioural Design Patterns are further classified as follows:
- Chain Of Responsibility Pattern
- Strategy Pattern
- Interpreter Pattern
- Iterator Pattern
- Mediator Pattern
- Memento Pattern
- Command Pattern
- State Pattern
- Observer Pattern
- Template Pattern
- Visitor Pattern
Strategy Design Pattern: It defines a family of functionality and encapsulates each one, and make them interchangeable. The Strategy Pattern is also known as Policy.
- It is designed to provide a substitute for sub-classes.
Command Design Pattern: It encapsulates a request under an object as a command and passes it to the invoker object. Invoker object looks for the appropriate object which can handle this command and pass the command to the corresponding object and that object executes the command. It is also known as Action or Transaction.
- It separates the object that invokes the operation with the object that actually performs the operation.
Observer Design Pattern: It defines a one-to-one dependency so that when one object changes state, all its dependents are notified and updated automatically. The Memento pattern is also known as Dependents or Publish-Subscribe.
- It illustrates the coupling between the objects and the observer.
- It provides support for broadcast-type communication.
JEE Design Patterns
They are concerned with providing solutions to the Java EE-based software applications and frameworks. These patterns are widely used in Spring. JEE Design Patterns are further classified as follows:
- MVC Design Pattern
- Dependency Injection Pattern
- DAO Design Pattern
- Business Delegate Pattern
- Intercepting Filter Pattern
- Service Locator Pattern
- Transfer Object Pattern
MVC Design Pattern: MVC Design Pattern is defined as follows:
- Models are basically objects used as blueprints for all of the objects that will be used in the application.
- Views are used to represent the presentational aspect of the information and data located in the models.
- Controllers control and act as both of the Models as well as Views. They serve as a connection between the Models and Views. Controllers are capable to instantiate, update and delete models. They load them with information and then send the data to the views to present to the end-user.
- It support multiple views for a model.
DAO Design Pattern: DAO is a pattern in which objects are dedicated to the communication with the Data Layer. These objects instantiate “SessionFactories” and handle all of the logic behind communicating with the database.
- It uses common calls to retrieve objects.
Overview of Design Patterns
- Java Design Patterns are designed to be reusable in multiple projects.
- They furnish solutions that help to define system architecture with ease.
- Design Patterns are capable to capture the software engineering experiences.
- They provide transparency to the design of an application.
- Design Patterns are provided by Expert Developers which prove that these are testified and well-proven solutions.
- Java Design Patterns provide clarity to the System Architecture and provide the possibility of building a better system.
Why is it important to choose Entri?
- Excellent online platform for all the Competitive Exams.
- Provides updated materials created by the Entri Experts.
- Entri provides a best platform with full- length mock tests including previous year question papers.
- You can download the app for free and join the required classes.
- Entri wishes you all the best for your examinations and future endeavours.
“YOU DON’T HAVE TO BE GREAT TO START, BUT YOU HAVE TO START TO BE GREAT.”