Overview of Design Patterns

Thilini Weerasinghe
4 min readMay 23, 2021

A design pattern plays major role in developing software applications. It can be introduced as well proven solution for solving a specific problem or task. It is independent from the programming languages and what it does is representing an idea and instructions to solve specific tasks, not implementation. As they are well-proved and designed by experts, using them in coding can make it flexible, reusable, reduce additional workload and easy to maintenance. Among the developers there is a best practices to use design patterns and if you want to become a professional software developer you need to have knowledge about at least few design patterns and its applications. In this article it is going to discuss about general facts of the design patterns that needs to know as a developer.

Types of design patterns 📝

In 1977 Christoper Alexander introduced design patterns but in latter year 1995, four authors named as Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides wrote a book named as Gang of Four — Design patterns, elements of reusable object-oriented software. Therefore following 23 design patterns are known as Gang Of Four (GOF) Design Patterns. They are categorized under three categories.

  1. Creational
  2. Structural
  3. Behavioral
Categorization of Design Patterns (Source: https://nitinmuteja.blogspot.com/)

👉 Creational Design Patterns

Main objective of design patterns coming under this category is to instantiation of particular class or object creation. These are can be categorized under two categories called Class creational and Object creational patterns. In class creation it uses inheritance concept effectively and object creation process uses delegation effectively to get the job done. There are five design patterns coming under this category.

  • Singleton
  • Factory Method
  • Abstract Factory
  • Builder
  • Prototype

👉 Structural Design Patterns

Structural design patterns are used to organize different classes and objects to create new functionality and form a large structures. It simplify the process of identifying relationships between entities. Structural design patterns are:

  • Adapter
  • Composite
  • Proxy
  • Fly Weight
  • Facade
  • Bridge
  • Decorator

👉 Behavioural Design Patterns

It manage the behaviour of the objects and identify the common communication patterns between the objects. Here are examples for the behavioural patterns.

  • Strategy
  • Observer
  • Template Method
  • Mediator
  • Chain Of Responsibility
  • Command
  • State
  • Visitor
  • Iterator
  • Interpreter
  • Memento

How to choose right design patterns

To choose the correct design patterns you need to have a sound knowledge regarding the design patterns. Here are some real world application scenario of the design patterns.

↔️ If you want to create only one instance of a class you have to choose singleton pattern. An examples is if we want to shared single DB connections with multiple objects or create a single error manger to handle the all problems in the application you can use singleton pattern

↔️ If you wants to create multiple instance of same objects while achieving loose coupling, the right choice is Factory pattern. If you have to use multiple DB servers like Oracle and SQL server for particular DB design, you should use factory pattern because it ensures the loose coupling between multiple objects

↔️ If you want to establish a relationship between two interfaces which are not compatible with each others, you have to use Adapter design pattern for that. It has capability to converts the interface of a class into another interface or class according to client expectation.

↔️ If you wants to extend the behaviour of a module without changing its source code, you can use Template design pattern for that. As an example in a particular project, a developer wants to add new requirements to the module without modifying the structure of the project, then he uses Template design pattern for that.

Advantages of using design patterns

  • Enhance the reusability of code
  • It captures the software engineering experiences
  • Provides high transparency in designing a software application
  • Decrease the work load of the developer
  • They provides well-proved and tested solutions for particular problem scenario
  • Built upon the expertise knowledge of experienced and professional software developers
  • It provides general system architecture to solve some sort of problem
  • Enable faster development

In this article it discussed about the three categories of design patterns named as creational, structural and behavioural and provides put 23 design patterns under these three categories. After that it explains about some real world application scenario of the design patterns and lastly it explains the advantages that can developers gain using design patterns. Hope you have basic idea about the design patterns and let’s go deep into few design patterns with coding examples in coming articles.

Stay Safe & Learn New Things!!! 😃

--

--

Thilini Weerasinghe

Currently working as an Associate Software Engineer at Virtusa. Has completed degree in B.Sc (Hons) Computing & Information Systems. After all I am a Human...