Fundamentals: Software Design Patterns

Hardik Patel
5 min readJan 16, 2024

--

Each and every developer wants to know what design patterns is, how and where we can use them. Before going into what are the patterns which can be helpful in our development journey, let’s look at the history of design patterns.

How and when were Design patterns found?

Following is the timeline which will help you understand why design patterns are currently in good shape.

1980 — Kent Beck and Ward Cunningham began applying the idea of pattern languages to software development.

1994 — Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides published their first version of the book called Design Patterns: Elements of Reusable Object-Oriented Software. This book, often referred to as the “Gang of Four” book, popularized the use of design patterns in software development.

If you are really interested in reading that book, here is the link to buy — Design Patterns: Elements of Reusable ObjectOriented Software book

They identified 23 classic design patterns, categorized into three groups.

  • creational
  • structural
  • behavioral.

This book became a bestseller and had a profound impact on the field of software development.

Since then, design patterns kept evolving and were applied to various software development contexts.

1995 — The GoF book is published and becomes a bestseller.

1997 — The JProbe profiler is released, which includes support for identifying design patterns in Java code.

2002 — The book Pattern Languages of Program Design is published, which introduces a more formal approach to design patterns.

2004 — The Eclipse Platform 3.0 is released, which includes a design pattern plug-in for identifying and using design patterns in Java code.

2010s — Design patterns are increasingly used in web development, mobile development, and other software development domains.

Today, design patterns are a recognized and valuable tool for software developers. They can help to improve code quality, maintainability, and reusability.

Because the use of design patterns is not always appropriate and can fit your problem, understanding and applying them can make you a better software developer.

Please follow me on medium so you will get notified about other important articles, which I will write.

Now let’s see how many design patterns we have as of today. If I miss any design pattern, please put that in the comment box.

Creational Design Patterns

Creational design patterns are all about how you create objects in your software. They provide different mechanisms for object creation, aiming to solve common problems and make your code more flexible, reusable, and maintainable.

Following patterns can be used to create objects in different situations.

  • Factory Method pattern: Defines an interface for creating objects, but let subclasses decide which specific type of object to create. This is like having a factory with different production lines for different products. Design Patterns in Python — Factory | by Hardik Patel | Medium
  • Abstract Factory pattern: Creates families of related objects without specifying their concrete classes. Imagine a furniture factory that makes different sets (bedrooms, kitchens) in a coordinated style. Design Patterns in Python — Factory | by Hardik Patel | Medium
  • Singleton pattern: Ensures that only one instance of a class exists throughout the application. This is like having a single CEO in a company. Design Patterns in Python — SingleTon | by Hardik Patel | Medium
  • Prototype pattern: Lets you copy existing objects without making your code dependent on their classes. Think of it like taking a mold of an object to create a replica.
  • Builder pattern: Constructs complex objects step-by-step, allowing you to customize different parts without needing to write a constructor with many parameters. It’s like building a house by assembling different components like walls, roof, and windows.

Structural Design Patterns

Structural design patterns deal with how to compose classes and objects to form larger structures. In simpler terms, they help you build complex systems out of smaller building blocks in a flexible and efficient way.

Following patterns are popular structural design patterns-

  • Adapter pattern: Lets incompatible interfaces work together by translating between them. Imagine plugging a different device into your power outlet with the help of an adapter.
  • Bridge pattern: Separates an abstraction (interface) from its implementation, allowing independent development and variation of each. Think of a car with a customizable engine under the same hood.
  • Composite pattern: Treats individual objects and groups of objects (hierarchies) uniformly. It’s like a team where each member and the entire team can take on tasks.
  • Decorator pattern: Dynamically adds new functionality to an object without modifying its existing structure. Imagine putting new accessories on a bike to enhance its capabilities. Decorator Design Pattern in Python | by Hardik Patel | Medium
  • Facade pattern: Facade pattern allows to hide complexity of system and provide simple interface to client of the service. Think of a single control panel for managing a smart home system. Design Patterns in Python — Facade | by Hardik Patel | Medium
  • Flyweight pattern: Shares common parts of state between similar objects to reduce memory usage. It’s like using the same letters to form different words efficiently.
  • Proxy pattern: Provides a controlled interface to another object, adding protection or additional processing steps. Imagine a receptionist answering calls for an executive. Python Design Patterns — Proxy Pattern — Controlling object access | by Hardik Patel | Medium

Behavioral Design Patterns

Behavioural design patterns focus on the communication and collaboration between objects in your software. They define how objects interact with each other and how they respond to events and changes. In essence, they’re focused on “how things work” rather than “what things are.

Let’s look at the following popular behavioral design patterns-

  • Observer Pattern: Let objects subscribe to and be notified about changes in other objects (like stock prices or news updates). Imagine multiple investors watching the same stock ticker. Python Design Patterns — Observer Pattern | by Hardik Patel | Medium
  • Chain of Responsibility Pattern: Passes a request along a chain of potential handlers until one handles it, promoting modularity and flexibility in handling different scenarios. Think of a help desk where requests move through different departments until resolved.
  • Command Pattern: Encapsulates an action as an object, allowing for queuing, scheduling, and undo/redo features. Imagine recording and replaying different moves in a video game.
  • Template Method Pattern: Defines the skeleton of an algorithm with specific steps, letting subclasses define and vary specific parts. Think of a baking recipe with core steps (mixing, baking) but customizable ingredients and timings. Python Design Patterns — Template method pattern | by Hardik Patel | Medium
  • Strategy Pattern: Lets you dynamically change an object’s behavior by choosing an implementation of an algorithm at runtime. Imagine choosing different attack moves for a character in a game.

All three types of design patterns have their own benefits. Please go through each and every design patterns. Having understanding of all of them, you will be able to apply any of them wisely in your problem.

I hope you have got basic understandings of Software Design Patterns. I will keep adding articles around all design patterns separately and will update this one with link of that article.

Thank you for reading and keep learning.

Please follow me on medium so you will get notified about other important articles, which I will write.

--

--

No responses yet