A Complete Guide on Design Pattern in Java

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Uses of Design Patterns

Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.

Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn’t require specifics tied to a particular problem.

In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Common design patterns can be improved over time, making them more robust than ad-hoc designs.

By using the design patterns you can make your code more flexible, reusable, and maintainable. It is the most important part because java internally follows design patterns.

If you want to become a professional software developer, you must know some popular solutions(design patterns) to the coding problems.

Advantage of design pattern:

  1. They are reusable in multiple projects.
  2. They provide the solutions that help to define the system architecture.
  3. They capture the software engineering experiences.
  4. They provide transparency to the design of an application.
  5. They are well-proved and testified solutions since they have been built upon the knowledge and experience of expert software developers.

We must use the design patterns during the analysis and requirement phase of SDLC(Software Development Life Cycle). It provides information based on prior hands-on experiences.

Categorization of design patterns:

Basically, design patterns are categorized into two parts:

  1. Core Java (or JSE) Design Patterns.
  2. JEE Design Patterns.

1. Core Java Design Patterns

In core java, there are mainly three types of design patterns, which are further divided into their sub-parts:

1.1 Creational Design Pattern

• Factory Pattern
• Abstract Factory Pattern
• Singleton Pattern
• Prototype Pattern
• Builder Pattern.

1.2 Structural Design Pattern

• Adapter Pattern
• Bridge Pattern
• Composite Pattern
• Decorator Pattern
• Facade Pattern
• Flyweight Pattern
• Proxy Pattern

1.3 Behavioral Design Pattern

• Chain Of Responsibility Pattern
• Command Pattern
• Interpreter Pattern
• Iterator Pattern
• Mediator Pattern
• Memento Pattern
• Observer Pattern
• State Pattern
• Strategy Pattern
• Template Pattern
• Visitor Pattern

2. JEE or J2EE Design Patterns

J2EE design patterns are built for developing Enterprise Web-based Applications.

In J2EE, there are mainly three types of design patterns, which are further divided into their sub-parts:

2.1 Presentation Layer Design Pattern

• Intercepting Filer Pattern
• Front Controller Pattern
• View Helper Pattern
• Composite View Pattern

2.2 Business Layer Design Pattern

• Business Delegate Pattern
• Service Locator Pattern
• Session Facade Pattern
• Transfer Object Pattern

2.3 Integration Layer Design Pattern

• Data Access Object Pattern
• Web Service Broker Pattern

Software Engineer at Virtusa (Pvt) Ltd.