Gang of Four Design Patterns: #1

Tisha J.
4 min readJan 6, 2023

--

Hi guys, ever since I have learnt and seen some great applications of the software design patterns, I have always wanted to write about the GANG OF FOUR (GOF) design patterns used for software design and construction and highlight its importance and beauty to all those aspiring software engineers.

credit: gpcoder

But, first let’s start with understanding what are these design patterns? and why it’s important to learn and realise the applicability of these design patterns, real quick.

What is a software design pattern?

> Have you found yourself following a common pattern like “intro-description-outro” while you write short notes on subjects in your school examinations and stuff or have you thought of how bakers at cafes manage heavy order hours for say pizza to cater to a wide range of orders? They might keep the pizza base ready and just add the toppings based on different customer’s preferences! These are some of the many examples where we use some patterns of solution to particular recurring problems. And following these does help make our job easy and efficient, ain’t it?

Thus, the idea is pretty simple. We can think of design patterns as reusable code skeletons or blueprints or particular design-level ways of solving problems based on a given software context, so as to make our software more robust, scalable, maintainable and marketable over time. Combinations of these forms the building blocks of some great software architecture. Thus, when you come across a particular pattern of problem, you customise the design pattern which is meant to solve the problem based on the given context.

It’s quite like, we see yourself using a particular kind of knife to cut fruits, but a different kind (scalpel) is used by surgeons in OT, but that both serve a common kind of activity, i.e. cutting. Thus, it’s intuitive to understand that we see common patterns in some set of problems and attempt to define ways to solve them more elegantly.

Design is not just what it looks like and feels like. Design is how it works.” –Steve Jobs.

What are GOF design patterns?

> Well, they are valuable set of 23 design patterns, defined by Gang of Four, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

You can read more about them in the book, Design Patterns: Elements of Reusable Object-Oriented Software (affiliate). The book introduces the GOF design patterns in an elegant way. Each pattern also includes code that demonstrates how it may be implemented in object-oriented programming languages like C++ or Smalltalk. This book is highly recommended to keep the design pattern asset handy to you. Or, if you stick to java development environment, feel free to check out the book, Software Design Patterns for Java Developers (affiliate).

GOF design patterns are of three categories, creational, structural, and behavioural design pattern. We will be exploring each of them throughout a series of some articles.

Why software design patterns?

> Well, users and software customers’ demands keep on changing or growing and a software has to evolve and upgrade its current version to suit the customers expectations and cater the services they demand. It’s a matter of evolving forms with changing demands, so that the software is more useful and usable. Now such a version update or upgrade, generally, should not break an existing software feature or introduce new bugs in the codebase, as such an incident can turn into a blunder costing millions by the organisation to fix bugs in a large scale deployed software. Further, it can question an organisation’s reputation, customer service and credibility.

Thus, it’s evidently important to build a software not only to make it work for the desired features but also program those in a way that can be extended safely and easily in the future in case of feature addition or upgrade. A robust software is the one that is extensible, maintainable and scalable.

memegenerator.net

For instance, suppose you are working on a large project of making smart watches which can tell calories burned, distance travelled and pulse rate. Now, say the marketing or user research team reports to you that the customers are also interested in knowing their blood pressure at any point of time. Now, the integration of this new feature in your smart should not break the older features. The build of the existing smartwatch must be extensible to make it easy for the developers to add and deploy that new feature easily.

Understanding the applicability of design patterns in software architecture and code marks the difference between software engineers and programmers!

Cr. me.me

“The best designers will use many design patterns that dovetail and intertwine a greater whole” — Erich Gamma

So, I hope after this you would be knee on exploring the design patterns out there, and everytime you code, pause for a bit, take a deep breath and think how scaleable and maintainable your code is!

Hope you had a worthy time reading this. Feel free to share your ideas or reach out 🙌 at linkedIn, github, subscribe, follow me here and share this or buy me a coffee ❤. Till then see you with the starters of GOF patterns!

--

--

Tisha J.
0 Followers

I am an experienced programmer, with enormous curiosity❤ for machine learning, DSA; and an open-source enthusiast