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