Design Patterns

Sanduni Jayaweera
3 min readMay 23, 2021

As you know, there are human being who are expertise to do some task. For an instance, think about the carpenters. They can make great innovations with normal tree which you may not be able. Also, different carpenters have unique set of skills while decorating, painting them. They take these abilities with the time and their experiences and thereby they can decrease the development time and effort by this expertise.

Likewise, in the programming world we can use these design patterns to make the programmer’s work easy. Because, these design patterns are help for developers to use them with their coding to make the code readable, less complex and to save the both time and memory. The design pattern avoid to repeat same thing again and again. Thereby your source code will save the memory as well time.

I think now you may have precise knowledge about the design pattern. In a regular definition: The design pattern is a blue print which you can customize to solve your occurring problems.

Reference: https://refactoring.guru/design-patterns/java

The idea of design patterns are proposed by the 4 authors of a book called Design Patterns: Elements of Reusable Objects-Oriented Software which is published in 1994. These authors are, Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm knows as Gang of Four (GoF). In this book they discovered only 23 patterns related with object-oriented programming and since then so many patterns have been discovered.

Each pattern has 4 major parts. They are,

  1. Pattern name: Should be able to address the problem even by looking at it.
  2. Problem: Specify clearly about the which problem is addresses by the specific pattern.
  3. Solution: Present how can we address the mentioned problem through our pattern using Object-Oriented Programming (OOP)language that we used.
  4. Consequences: Represents the results that we can have by applying the specific pattern.

Pros of using Design Patterns

  • Design patterns already has tried and test solutions.
  • Easy to conduct the unit test.
  • Development will be more flexible to adopt with the new changes.

Cons of using Design Patterns

  • If you are not aware of where to use the pattern clearly, then it will mess-up whole code.
  • Sometimes, newbies may hard to concepts in there.

|Categorization of Design Pattern

In the book of GoF, they categorize their implemented design patterns into 3 categories with each and every patterns as shown below.

Reference: https://techvidvan.com/tutorials/java-design-patterns/

Creational Design Patterns

  • All the patterns belongs to creational pattern are basically deals with the object creation or instantiation.
  • Also, the creational patterns are used when the system emphasize more on object creation than the class inheritance.
  • In creational patterns, it encapsulate the concrete class and hide instance creation.

Structural Design Patterns

  • We know, everything in OOP are considered as objects and classes.
  • So, in the structural pattern, every pattern describe different ways which we can used to compose these objects and classes to provide the bigger structures.

Behavioral Design Patterns

  • As its name, behavioral patterns are describe about the communication pattern over the objects.

In my next articles, we are going to discuss about the different patterns under these major 3 patterns in detailed manner.

Stay Safe !!!

--

--