Getting familiar with design patterns in Java


In this article, I intend to introduce design patterns to the readers and how useful it is to adept to the standard practices of software engineering.

What are design patterns?


In the context of software engineering, a design pattern is usually referred to as a common and repeatable solution that has been tried and tested and has proven to be an effective resolution to a particular problem in this domain. The design patterns are solution approaches and not a framework. They are established on the basic principles of object oriented methodology. It adheres to programming to an interface rather than the implementation and also, prefers composition to inheritance. Usually patterns are alternative and similar. They give a hint to sort out the problem efficiently and are discoverable and one may lead to the other.

Although, design patterns make quite a robust software engineering tool, they are not considered to be finished products or ready to use solutions, rather they act like templates that can give a baseline structure to multiple scenarios and they have the flexibility to be extended and improved upon. The coding efficiency and the maintainability of the code enhances eventually. An important feature that distinguishes analysis patterns from design patterns is that the former are designed to target domain architecture whereas design patterns are meant for implementation mechanism. Also, analysis patterns are of high level and are function oriented.They make the code very easy to comprehend once a developer has become familiar and friendly with them. Two common uses of design patterns are:

1. They provide a common language to the developers to express themselves among each other.
2. Design patterns encourage sticking to standard practices and capture solutions that have been applied to the problems sharing similar traits.

Also Read: Build up your career as a PHP programmer

Categories in design patterns


The design patterns in java can be broadly classified as:

1. Creational patterns: They prescribe ways in which the objects can be created. They play a decisive role when the class is instantiated. They client class is not aware of what, when and how they are initiated. It knows only about the interface that it implements or the abstract class that it extends. The most common examples of creational patterns can be singleton pattern and factory pattern.
2. Structural pattern: This category of design patterns determine how the classes and objects. Inheritance and composition are the primary concerns of these patterns. Adapter, decorator and proxy patterns are the common structural patterns.
3. Behavioral Patterns: The behavioral class of patterns prescribe how the objects interact with one another. Through these patterns, complex behavior can be managed by specifying the object responsibilities and their communication with each other. Observer pattern is one example of behavioral pattern. It is used when an application is implemented using MVC (model-view-controller) architecture and the data semantics is kept separately from the data itself. The next important behavioral patterns are strategy and template patterns that support different implementations against a static set of behavioral aspects.
4. Concurrency patterns:Defines the way shared resources are accessed, coordinated or sequenced. Most of the concurrency patterns execute in a single thread. It has to be ensured that mutual exclusion of code sections (or fragments) is maintained. Example, single thread execution pattern.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: