Design Patterns – Introduction

design pattern is a general reusable solution to a commonly occurring problem in software design. Design patterns represent the best practices used by experienced developers to solve common problems.

Knowing only the concepts like inheritance, polymorphism, and encapsulation will not make you an expert object oriented developer. You must think about creating reusable, flexible and easy to maintain systems. You should know at least some design patterns to solve some frequent occurring design problems.

Principles of Design Patterns

  • Identify the components of your system that varies and keep them separate from what remains the same. In this way, you can change or extend the components that vary independently without affecting the components that remains same.
  • Program to an interface not an implementation.
  • Favour composition over inheritance. In other words, a “HAS-A relationship is better than IS-A“.

Advantages of Design Patterns

  • Design Patterns helps you to build reusable systems with good object oriented design qualities.
  • They capture the proven object oriented experiences. You don’t have to re-invent again.
  • It provides shared vocabularies that allows you to say more with less. It helps developers to communicate efficiently.
  • Design patterns let you write better code more quickly.
  • It specifies the best practices and solutions used the developers everywhere to solve a particular problems faced during software development.

Types of Design Patterns

Design patterns can be broadly classified in three categories: Creational, Structural and Behavioral design patterns.

  • Creational Patterns : These design patterns deal with the problem of creating object while hiding the logic and complexity associated with it. Singleton Pattern, Factory Pattern, Builder Pattern etc comes under creational design patterns.
  • Structural Patterns : These design patterns are used to define relationship between classes, objects and various entities. Adapter Pattern, Bridge Pattern, Proxy Pattern etc comes under structural design patterns.
  • Behavioral Patterns : These design patterns deal with communication between objects. Command Pattern, Mediator Pattern, Observer Pattern, Strategy Pattern etc comes under behavioral patterns.

Important Points About Design Patterns

  • Patterns are not invented, they are discovered over time by experienced developers.
  • Design pattern won’t give you code or guarantee an absolute solution. It is a general solution of a commonly occurring problem that can be used in many different situations.
  • Standard Libraries and frameworks are not design patterns. They are the implementations of design patterns.
  • Most design patterns helps us to extend and vary components of a system independently of each other.