Design Patterns Tutorial With Examples

Design patterns are a popular topic in software development. A design pattern is a common, well-described solution to a common software problem. Sensible use of design patterns results in increased code maintainability, since in addition to being a good solution to a common problem, design patterns can be recognized by other developers, thus reducing the learning curve when dealing with a particular piece of code.
Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.
Design patterns are proven solutions approaches to specific problems. A design pattern is not a framework and is not directly deployed via code.
Java Design Patterns

Design Pattern have two main usages:

  • Common language for developers: They provide developers a common language for certain problems. For example if a developer tells another developer that he is using a Singleton, the another developer (should) know exactly what this means.
  • Capture good practices: Design patterns capture solutions which have been successfully applied to problems. By learning these patterns and the related problem, an unexperienced developer learns a lot about software design.

Advantages of using design patterns are:

  1. Design patterns help you analyze the more abstract areas of a program by providing concrete, well-tested solutions.
  2. Design patterns help you write code faster by providing a clearer picture of how you're implementing the design.
  3. Design patterns encourage code reuse and accommodate change by supplying well-tested mechanisms for delegation and composition, and other non-inheritance based reuse techniques.
  4. Design patterns encourage more legible and maintainable code by following well-understood paths.
  5. Design patterns increasingly provide a common language and jargon for programmers.

Types of design patterns

Design Patterns can be divided into three categories – creational, structural, and behavioral design patterns.

Creational Design Patterns

There are five types of Creational Patterns.
  1. Factory Pattern
  2. Abstract Factory Pattern
  3. Builder Pattern
  4. Prototype Pattern
  5. Singleton Pattern

Structural Design Patterns

There are seven structural patterns described. They are as follows:
  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. Flyweight Pattern
  7. Proxy Pattern

Behavioral Design Patterns

The behavioral patterns are:
  1. Chain of Resposibility 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

Hope we are able to explain you Design Patterns, if you have any questions or suggestions please write to us using contact us form.(Second Menu from top left).

Please share us on social media if you like the tutorial.