Design Patterns in Java – Introduction

In coming next few posts, we will build a series of posts to discuss design patterns in Java. In this introductory post, we will give a brief idea about design patterns.

What are design patterns?

Design patterns are programming strategies independent of programming language to build a solution for common object-oriented programming problems. One of the major benefits of design patterns is that the most code is reusable and easily maintainable.

Example of design pattern in real world?

To understand what exactly design patterns are, let’s consider a real life example. Suppose we have an animal class. All the subclasses for animals like Elephant, Dog, Cat can be built by using methods to make these objects.

An abstract factory is a design pattern, that can be used in this example.


abstract class AbstractAnimalFactory

{

public Elephant makeElephant() {

return new Elephant();

}

public Dog makeDog(){

return new Dog();

}

}

 

abstract class Animal{

 

}

class Elephant extends Animal{

 

}

class Dog extends Animal{

 

}

 

Types of design patterns

Based on their purpose, design patterns are divided into three types of patterns creational, structural and behavioral. Further, each of these design patterns have sub-types.

Creational Design Pattern

  1. Singleton Design Pattern
  2. Factory Pattern
  3. Absolute factory Pattern
  4. Builder Pattern
  5. Prototype Pattern

Structural Design Pattern

  1. Adapter Pattern
  2. Composite Pattern
  3. Proxy Pattern
  4. Flyweight Pattern
  5. Facade Pattern
  6. Bridge Pattern
  7. Decorator Pattern

Behavioral Design Pattern

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

In coming posts, we will discuss each design pattern with a production-ready example.

Advantages of design patterns

  1. Reusable in multiple projects
  2. Capture the complete experience of software engineering
  3. Provide clarity to system architecture

Conclusion

In this post, we discussed a simple introduction to design patterns. In coming posts, we will build actual design patterns to show how design patterns work.

References

  1. Design patterns in Java
  2. Design Patterns Brief Introduction
Advertisements

One thought on “Design Patterns in Java – Introduction

  1. Pingback: Design Patterns – Singleton Pattern – Part II | Code Complete

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s