Learn How To Implement Design Patterns Using Java and J2EE

0
2723
Design Patterns

In this chapter, we are going to discuss on the concept of Design Patterns which denote the best practices in the object-oriented software development. Almost all software developers face general problems in their day to day life during software development. These design patterns not only provide the best practices, but also a common solution to these general problems. These solutions, which are now standardised through designers and their patterns, were actually obtained by many experienced software developers through trial and error approach over a period of time in the software industry. These design patterns help novice developers learn about the software design very swiftly and easily.

In this tutorial, we are going to implement design pattern concepts by following the step by step approach using Java /J2EE as the programming language. Therefore, it is an assumption made here is that the readers of this tutorial are well versed with the basic java programming concepts.

Invention of Design Pattern:
Design Patterns were actually invented as an architectural concept by Christopher Alexander in the year of 1977. A design pattern book by the gang of four (GOF) refers to a popular book ( Design Patterns – Elements of Reusable Object-Oriented Software) written by four experienced developers ( Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm) on the concept of Design Pattern in the Software development. This book was published in the year of 1994. It is mainly based on best practices and the following ideologies of object orientated design.
• Supporting program to an interface and not an implementation.
• Supporting object composition over inheritance.

Application and use of Design Patterns
Object-oriented design patterns characteristically demonstrate the relationships and interactions between the class objects, without stipulating the final application class objects which are involved. They can be observed as a structured approach to computer programming between the levels of a software design paradigm and a concrete algorithm. The following two are the main usages of the Design Patterns by the software developer in any software application development.

1. Provision for Common platform for the software developers: Design patterns help to provide a standard terminology to novices as well as experienced software developer which are precise to a particular problem or scenario. E.g., a singleton design pattern indicates the use of single object in a program. Therefore, all developers who are familiar with the single design pattern can easily make use of the single object in their program and can easily transfer the knowledge to other team members who are going to program on a singleton design pattern.
2. Best Programming Practice: Design patterns provide the best solutions to the programming problems or scenarios which a software developer usually face in their day to day coding practices. Such standardised solutions through the design patterns were actually obtained by many experienced software developers through a trial and error approach over a period of time in the software industry. Therefore, these design patterns help novice developers to learn about the software design very swiftly within no time.

Categories of the Design Patterns
Referring to the popular book of Design Patterns – Elements of Reusable Object-Oriented Software, there are total 23 design patterns. These design patterns can be categorized into the following three categories:

• Creational design pattern.
• Structural design pattern.
• Behavioral design patterns.

Another category of design pattern other than from this book is known as J2EE design pattern. The following is the explanation for all of these categories of the design patterns,

S No.

Pattern

Description

1.

Creational Pattern

Creational design patterns help provide a common and a very simple way to create objects and hide the actual creation logic. In this pattern, rather than instantiating the objects, we can directly use new operator. This pattern provides developers an increased flexibility in deciding which objects are required to be created for a given application use case during coding. E.g., Abstract factory design pattern, Builder design pattern, Factory method design pattern, Lazy initialization design pattern, Prototype design pattern, Singleton design pattern, etc.

2.

Structural Pattern

Structural design patterns concern class and object composition. In this design pattern, the concept of inheritance is used for the composition of interfaces and it describes the ways to compose objects in order to obtain new functionalities. E.g., Decorator design patterns, Façade design pattern, Composite design pattern, Adapter design pattern, etc.

3.

Behavioral Pattern

Behavioral design patterns are precisely concerned with communication between the objects. E.g., Iterator design pattern, Interpreter design pattern, Chain of responsibility design pattern, Template method design pattern, Mediator design pattern, etc.

4.

J2EE Pattern

J2EE design patterns are precisely concerned with the application presentation tier. These patterns are exclusively recognized by Sun Java Center. E.g., Session Façade, Value Object Assembler, Service Locator Pattern, Business Delegate, Service Locator, Composite Entity, Value Object, Data Access Object, Service to Worker, Intercepting Filter, View Helper, Composite View, Dispatcher View, etc.

Conclusion
In this chapter, we discussed the overview, concepts, application and categorization of various Design Patterns which obey standardized coding practice and help novice developers to learn about the software design very swiftly within no time.

LEAVE A REPLY

Please enter your comment!
Please enter your name here