Go Design Pattern: Prototype

What is Prototype Pattern? The Prototype pattern is a creational design pattern that allows you to create new objects by cloning existing instances rather than creating them from scratch. It’s particularly useful when object creation is expensive or complex, and you want to avoid the overhead of initializing objects repeatedly. Think of it like having a template or blueprint that you can copy and modify as needed. I’ll demonstrate how this pattern can significantly improve performance and simplify object creation in Go applications....

March 15, 2024 · 6 min · Rafiul Alam

Go Design Pattern: Builder

📚 Go Design Patterns 🔨Creational Pattern ← Adapter Pattern 📋 All Patterns Strategy Pattern → What is Builder Pattern? The Builder pattern is a creational design pattern that constructs complex objects step by step. It allows you to produce different types and representations of an object using the same construction code. Think of it like assembling a custom computer - you choose the CPU, RAM, storage, and graphics card piece by piece to build exactly what you need....

February 27, 2024 · 10 min · Rafiul Alam

Go Design Pattern: Strategy

📚 Go Design Patterns 🎯Behavioral Pattern ← Builder Pattern 📋 All Patterns Decorator Pattern → What is Strategy Pattern? The Strategy pattern is a behavioral design pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets you select algorithms at runtime without altering the code that uses them. Think of it like choosing different routes to reach the same destination - each route (strategy) gets you there, but some might be faster, cheaper, or more scenic....

February 13, 2024 · 9 min · Rafiul Alam

Go Design Pattern: Observer

What is Observer Pattern? The Observer pattern is a behavioral design pattern that defines a one-to-many dependency between objects. When one object (the subject) changes state, all its dependents (observers) are notified and updated automatically. Think of it like a newsletter subscription - when new content is published, all subscribers get notified. I’ll demonstrate this pattern with a practical scenario that shows how powerful it can be in Go applications....

January 30, 2024 · 7 min · Rafiul Alam

Go Design Pattern: Factory

What is Factory Pattern? The Factory pattern is a creational design pattern that provides an interface for creating objects without specifying their exact classes. It’s like having a factory that produces different types of products based on what you request, but you don’t need to know the intricate details of how each product is made. I’ll walk you through a practical scenario that demonstrates the power of the Factory pattern in Go....

January 16, 2024 · 4 min · Rafiul Alam

Go Design Pattern: Adapter

📚 Go Design Patterns 🏗️Structural Pattern 📋 All Patterns Decorator Pattern → What is Adapter? The Adapter pattern is probably the most used design pattern in software engineering. It allows objects/classes of different abstracts/signatures/blueprints to collaborate. I will guide you through a practical scenario that will make it easier to understand the Adapter pattern. Let’s start with a scenario: Hack the API Suppose you are creating an OpenAI API client....

January 2, 2024 · 4 min · Rafiul Alam

Go Design Pattern: Singleton

What is Singleton? The Singleton pattern is a design pattern that ensures a class has only one instance and provides a global access point to that instance. I will keep the post as simple as possible as our brain can process a little at a time (don’t know about yours, mine can’t). Let’s start with a scenario: Database connection You want to connect to the database of a service to fetch some information....

December 29, 2023 · 4 min · Rafiul Alam