What is Design Patterns?

Design patterns are the solutions to commonly occuring problems in our code. We can say design patterns are pre-defined blueprints that we can customize to solve a recurring design problem in our system and these are industry standards and almost everyone follow these patterns. Design patterns are not the solution, instead it is a approach or template which you implement in your code for how to solve a problem in different situations.

Design patterns are language independent, you can use design patterns across any object oriented langauge. e.g. java, python, c++, php etc.

The concept of design patterns is borrowed from the field of building architechture. Design patterns were first explained by architect Christopher Alexander in his book “A Pattern Language: Towns, Buildings, Construction ( Oxford University Press, 1977 )”. The concept he introduced and called patterns. And researchers in other fields caught the attention of this concept, especially those developing object oriented software.

In general, a pattern has four essential elements:

  • Pattern name: Pattern name is a handle, which we can use to describe a design problem, its solutions, and consequences in a word or two.
  • Problem: Problems describes in which situations we have to apply pattern.
  • Solution: Solution describes ins and outs of the design including its elements, their relationships, responsibilities, and collaborations.
  • Consequences: Consequences are results and trade-offs of applying the pattern.

Why do we need design patterns?

In our system or code for commomly occuring problems we need something which can overcome or solve these problems so that these problems wouldn’t come again. And Design pattern are the best solution for solving these problems that’s why we need design patterns in our system.

We need design patterns to solve some commmon problem e.g.

  • How to properly create a class: What are variables it should have, how to create methods.
  • How to write loosely coupled code: Which is flexible and easily maintainable.
  • How to make API Design: How to make Better API design.
  • How to instantiate an object: Do we need a method to create a instance, or need a helper class to instantiate a object, or instantiate object using new operator.
  • Help in organizing the logic: Developer refactor their code according to the changes and patterns do help in organizing the logic and their code.
  • How to interact between objects: Pattern helps how to pass a data from one object to another object and how to call a function from one object to another object etc.
  • How to write resuable code: Patterns help us to write resusable code so that we can resue later.
  • Easier communication between developers: Make easier to communicate between developers.

Benefits of Design patterns

There are a numbers of benefits of the design patterns: e.g.

  • It provides a catalog of solutions.
  • Patterns are language neutral so any language based on object orientation can implement the design pattern.
  • It decrease the complexity of the system.
  • Design patterns are highly flexible and can be used in any type of application.
  • Other developers who refactoring the code or writing a new logic, won’t have to struggle to understand the code as structured are well maintainted with design patterns.
  • Design patterns allow efficient communication between software developers.
  • Following best practices then it helps to build more robust software.
  • It make software Development faster.
  • It improves code readability for coders and architects familiar with the patterns.
  • It makes loosely coupled application.
  • It provides code of reusability

What is Gang of Four (GOF)?

In 1994, a book was published titled “Design Patterns: Elements of Reusable Object-Oriented Software”. In this book authors have explained the design patterns for software development. This book was written by four authors named as : Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. And these four authors of this book often referred to as Gang of Four (GOF).

Next ❯
Types of Design Pattern

All Rights Reserved. ReadAndCare