Types of Design Patterns

Previously, we discussed what is design patterns, GoF and J2EE patterns. See here:- Design Patterns. Now, let us see the different types of design patterns used in Java.

There are many pattern catalog are available but mainly two of them are very popular.

  1. GoF Design Patterns:- The GoF design patterns deal with the reoccurring problems of OOP.
  2. J2EE Design Patterns:- It gives problem and solution related to JEE (Java Platform Enterprise Edition) based layered application development.

Types of GOF Design Patterns

The GOF design patterns are classified into three categories,

  1. Creational Patterns:- Concern the process of object creation. It talks about object creation-related problems and solutions.
  2. Structural Patterns:- Deal with the composition of classes and objects. It gives problems and solutions related to how to create complex objects by combining multiple small objects.
  3. Behavioral Patterns:- Deal with the interaction of classes and objects. It gives the problems and solutions related to communication between classes, and communication between objects.

Creational Patterns

The creational design patterns are the design patterns that deal with object creation mechanisms i.e. how an object can be created. It gives solutions to create objects in a manner suitable to the situation. The basic form of object creation (using the “new” keyword) could result in design problems or added complexity to the design. Creational design patterns solve those problems by somehow controlling this object creation.

All the creational patterns define the best possible way in which an object can be instantiated. These describe the best way to create object instances. According to GOF, the creational patterns can be categorized into five types:

  1. Singleton Pattern
  2. Factory Pattern
  3. Abstract Factory Pattern
  4. Prototype Pattern
  5. Builder Pattern and e.t.c.

Structural Patterns

Structural design patterns are design patterns that ease the design by identifying a simple way to realize the relationship between entities. Structural patterns describe how objects and classes can be combined to form larger structures. According to GOF, the structural pattern can be realized in the following patterns:

  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. FlyWeight Pattern
  7. Proxy Pattern and e.t.c.

Behavioral Patterns

Behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication i.e. prescribes the way objects interact with each other. They help make complex behavior manageable by specifying the responsibilities of objects and the ways they communicate with each other. The 11 behavioral design patterns are:

  1. Chain of Responsibility Pattern
  2. Command Pattern
  3. Interpreter Pattern
  4. Iterator Pattern
  5. Mediator Pattern
  6. Momento Pattern
  7. Observer Pattern
  8. State Pattern
  9. Strategy Pattern
  10. Template Pattern
  11. Visitor Pattern

J2EE/JEE Design Patterns and their types

J2EE plateform/application are multitiered system. We view the system in terms of tiers. A tier is a logical partition of related concerns. Tiers are used for the separation of concerns. Each tier handles its unique responsibility in the system. Each tier is a logical separation and has a minimal dependency with other tiers.

A typical JEE application contains 5 layers,

  1. Client Tier:- Application clients, applets and e.t.c.
  2. Presentation Tier:- JSP, Servlet and e.t.c.
  3. Business Tier:- RMI, EJB’s, and other business objects.
  4. Integration Tier:- JMS, JDBC, Connectors and e.t.c.
  5. Resource Tier:- Database, external systems, and e.t.c.

In JEE pattern catalog based on the above given layers, we have 3 categories of Design pattern.

  1. Presentation Tier Patterns
  2. Business Tier Patterns
  3. Integration Tier Patterns

Presentation Tier Patterns

This tier contains all the presentation tier logic required to service the clients that access the system. The presentation tier design patterns are,

  1. Front Controller
  2. Application Controller
  3. Intercepting Filter
  4. Context Object
  5. View Helper
  6. Composite View
  7. Service toWorker
  8. Dispathcer View

Business Tier Patterns

This tier provides the business service required by the application clients. The business tier design patterns are:-

  1. Business Delegate
  2. Service Locator
  3. Session Facade
  4. Application Service
  5. Business Object
  6. Composite Entity
  7. Transfer Object
  8. Transfer Object Assembler
  9. Value List Handler

Integration Tier Patterns

This tier is responsible for communicating with external resources and systems such as data stores and e.t.c. The integration tier design patterns are:-

  1. Data Access Object (DAO)
  2. Service Activator
  3. Domain Store
  4. Web Service Broker

Regularly used Design Patterns

Among these all design patterns, some patterns are quite regularly used design patterns in the projects. They are,

GoF PatternsDescription
SingletonIn any situation it allows JVM to create only one object.
FactoryProvides abstraction on the object creation process.
Factory MethodProvides the set of rules and guidelines for multiple factories when they are creating objects for the same family classes.
Abstract FactoryIt is a super factory or factory of factories. When we are working with multiple factories that create objects for different family classes, to make sure that all objects are created through the same factory go for the abstract factory.
TemplateThe class that contains the method of automating the sequence of operations to complete the task having the flexibility of customizing certain operations.
BuilderAllows to create the complex object as the combination of multiple sub-objects having reusability of sub-objects.
Decorator/WrapperUseful to decorate the object with additional facilities without using inheritance.
AdapterTo make the class of one module compatiable to work with another module class we need to use adaptor.
FlyWeightIt makes the programmer to utilize minimum objects for maximum utilization by identifying intrinsic (sharable) state and extrinsic state.
J2EE PatternsDescription
Front ControllerEntry and exit point for all requests having mandatory system services.
Composite ViewRecommended to take common logics (Header and footer logics) in separate web components and to include their outputs in main web components.
Service LocatorThe class that contains lookup code to get the reference of external service component and maintains cache having to get reusability.
Business DeligateHelper to controller servlet to convert a) To convert VO to BO b) To translate technology-specific exceptions into application-specific exceptions. c) To perform transaction management.
Session FacadeThe special server-side external component that talks to multiple other external components to complete the task.
Message FacadeSame as the session facade but gives Asynchronous communication.
Data Access Objects (DAO)The class that separates persistence logic from other logic.
Intercepting FilterWeb components having optional services that can be enabled disabled dynamically.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Reply