Posts

Showing posts from September, 2024

Creational Design Pattern - Abstract Factory

Image
 There are 5 types of creational design patterns - Abstract Factory, Builder, Factory Method, Prototype and Singleton.  Abstract Factory Design Pattern Abstract Factory is used for creation of various types of similar objects. Before explanation about the structure of this pattern, take a look at the following diagram.    The Abstract Factory Pattern may seem complex at first, but once you understand its components, it becomes much easier to work with. Here's a simple breakdown of how it operates. It consists of six key components: Interface : An interface acts as a blueprint that multiple classes will implement. In this example, Food_Drink_Interface defines a food_drink ( ) method with an empty body. This method is implemented by multiple concrete classes such as Burger , Pizza , Coffee , and Tea . Abstract Factory : An abstract factory helps create related objects without needing to know which concrete class is being instantiated. In this case, Food_Drink_Fa...

What Is a Design Pattern and Why Should We Use It?

Introduction 🤔🧠💡 I often found myself asking: What is a design pattern, and why should I use it? Although my professor explained that design patterns make code more readable, cleaner, and easier to maintain, the concept still felt abstract to me. I understood the words, but not the real value behind them. My confusion started to clear after reading a quote by Christopher Alexander , the architect who introduced the idea of design patterns. “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.” This quote helped me realize that design patterns are not about copying code — they are about reusing ideas and solutions . Who Created Design Patterns? The concept of design patterns was first introduced in 1977 by Christopher Alexander , an architect. He used patterns to describe recurring p...