Design Patterns

What are design patterns?

Design patterns are important techniques to embody good design practice in system design. While system design, a system designer faces various difficulties to implement the same designs again and again. You can say there are various problems which can be solved with a common solution. Design patterns are techniques to provide a solution to common problems in a given context of system design.

design patterns

In Software Engineering, design patterns are used to enhance reusability resulting in preservation of previous experience gained through similar situations. The commonly occurring problems in designs are solved through a general solution which is applicable to a range of problems. These designs can not be translated directly into source code. These are not finished designs, but these are templates for how to resolve a problem in different contexts.

What is Gang of Four (GOF)?

The concept of design patterns in software development was introduced by Richard Helm, Erich Gamma, Ralph Johnson and John Vlissides in their book named “Design Patterns – Elements of Reusable Object-Oriented Software”. These four authors of the book are known as Gang of Four (GOF). According to them, patterns are based on object-oriented design. There are 23 patterns.

What are the uses of a design pattern?

Design pattern has many benefits including enhancement of the overall value of software. It speeds up the process of development by providing already tested paradigms. It helps in avoiding repetition of issues in increments. Design pattern helps in avoiding errors and improving code readability for architects and coders. It helps coders to use well understood and well-known names for software instructions. It is generic and can be applied to multiple scenarios.

Design patterns are already tested and tried solutions to common problems with least design errors. Even if you don’t use design patterns, these help to develop your thinking to organize your code in good and maintainable format.

In short, maintainability, reusability and ease of use are increased resulting in reduction of cost and time required to complete a product.

What are the disadvantages?

Each design pattern has large advantages. However, its disadvantages are related to designers understanding. Some designers can apply a design pattern to some problems only due to lack of understanding of context. Anyone can program in his own way. A pattern should be only adopted if a programmer is confident.

What are the types of design patterns?

There are 26 design patterns. They are classified based on their behaviours and properties. The patterns in each group are related to some extent and can be used together or independently. There are three major types:

  1. Creational
  2. Structural
  3. Behavioural

Based on properties and behaviours, each design pattern is assigned to one of the above-mentioned categories.

Creational Design Patterns:

Creational Design Patterns are related to instantiation of class and object creation. From the name of this category, it can be understood that it is something related to creation. Creational design patterns are further classified into class creation patterns and object creation patterns. Class creation follows inheritance in instantiation process while object creation uses assignment to get the task completed.

Following are the design patterns that are considered as creational design patterns.

  1. Abstract Factory
  2. Builder Design
  3. Factory Method
  4. Object Pool
  5. Prototype
  6. Singleton

Structural Design Patterns

From the word “Structural”, it can be predicted that we are talking about something related to structure like formation or composition of class and object. Such pattern is called structural design pattern.

Structural patterns are further classified into two sub-categories. Structural class design pattern uses inheritance to compose interfaces while structural object design pattern defines ways to compose objects to achieve new functionality.

  1. Adapter
  2. Bridge
  3. Composite
  4. Decorator
  5. Façade
  6. Flyweight
  7. Private Class Data
  8. Proxy

Behavioural Design Patterns

Behavioural design patterns are related to communication among objects of classes. These are related to behaviour of class and its objects. Following patterns belong to behavioural category.

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

What programming languages support design patterns?

A design pattern is not programming languages specific. Actually, any programming language following the object-oriented paradigm can be used to develop a product or project by adopting these patterns. Structural programming languages can not use these patterns, because these are designed for object-oriented languages, for example, Java, C++, C#, PHP etc.

Object-Oriented Paradigm includes the following concepts:

  • Abstraction
  • Encapsulation
  • Information Hiding
  • Separation of Concern
  • Modularization
  • Divide and Conquer
  • Separation of interface and implementation
  • Single Point Reference
  • Separation of Policy and Implementation
  • Primitiveness
  • Completeness
  • Sufficiency
  • Coupling
  • Cohesion

What is framework?

In computer programming, a framework is an abstraction which can be reused and extended by any programmer resulting in increased reusability of software.

Are design patterns frameworks?

Design patterns support reuse strategy and same is with framework. A framework is also intended to provide reusability. However, they are not same. Frameworks are more specific and partially completed software systems. They can be used in a specific application that can be extended further by adding additional source code. Whereas patterns are more general and more abstract. They are a description of the way through which a problem can be solved. A pattern does not follow any framework. But a framework can adopt multiple design patterns at a time.