Posts
Love Your Body
Never take your body for granted.
❤️Love your body❤️
Heart beats, lungs breathe, ears hear, eyes see, nose smells, mouth tastes, skin feels, brain thinks, hands work, legs walk, feet run, stomach digest, liver detox, kidney filter, bladder store, intestines absorb, pancreas regulate, gallbladder store, spleen filter, bones support, muscles move, joints connect, blood circulate, lymph flow, nerves transmit, hormones regulate, immune system protect, reproductive system reproduce, etc.
Grateful! & Healthy!
read morePosts
Template Method Pattern
Template Method is a behavioral design pattern that allows you to define a skeleton of an algorithm in a base class and let subclasses override the steps without changing the overall algorithm’s structure.
Golang Implementation Example: One Time Password (OTP) Functionality Let’s consider the example of One Time Password (OTP) functionality. There are different ways that the OTP can be delivered to a user (SMS, email, etc.). But irrespective whether it’s an SMS or email OTP, the entire OTP process is the same:
read morePosts
Iterator Pattern
Iterator is a behavioral design pattern that allows sequential traversal through a complex data structure without exposing its internal details.
Thanks to the Iterator, clients can go over elements of different collections in a similar fashion using a single iterator interface.
Golang Implementation Example: The main idea behind the Iterator pattern is to extract the iteration logic of a collection into a different object called iterator. This iterator provides a generic method of iterating over a collection independent of its type.
read morePosts
Command Pattern
Command is behavioral design pattern that converts requests or simple operations into objects.
The conversion allows deferred or remote execution of commands, storing command history, etc.
Golang Implementation Example: TV Remote Let’s look at the Command pattern with the case of a TV. A TV can be turned ON by either:
ON Button on the remote; ON Button on the actual TV. We can start by implementing the ON command object with the TV as a receiver.
read morePosts
Mediator Pattern
Mediator is a behavioral design pattern that reduces coupling between components of a program by making them communicate indirectly, through a special mediator object.
The Mediator makes it easy to modify, extend and reuse individual components because they’re no longer dependent on the dozens of other classes.
Golang Implementation Example: Railway Station Traffic System An excellent example of the Mediator pattern is a railway station traffic system. Two trains never communicate between themselves for the availability of the platform.
read morePosts
Memento Pattern
Memento is a behavioral design pattern that allows making snapshots of an object’s state and restoring it in future.
The Memento doesn’t compromise the internal structure of the object it works with, as well as data kept inside the snapshots.
Golang Implementation Example: The Memento pattern lets us save snapshots for an object’s state. You can use these snapshots to revert the object to the previous state. It’s handy when you need to implement undo-redo operations on an object.
read morePosts
Strategy Pattern
Strategy is a behavioral design pattern that turns a set of behaviors into objects and makes them interchangeable inside original context object.
The original object, called context, holds a reference to a strategy object. The context delegates executing the behavior to the linked strategy object. In order to change the way the context performs its work, other objects may replace the currently linked strategy object with another one.
Golang Implementation Example: Cache eviction strategy Suppose you are building an In-Memory-Cache.
read morePosts
State Pattern
State is a behavioral design pattern that allows an object to change the behavior when its internal state changes.
The pattern extracts state-related behaviors into separate state classes and forces the original object to delegate the work to an instance of these classes, instead of acting on its own.
Golang Implementation Example: Vending Machine Let’s apply the State Design Pattern in the context of vending machines. For simplicity, let’s assume that vending machine only has one type of item or product.
read morePosts
Singleton Pattern
Singleton is a creational design pattern, which ensures that only one object of its kind exists and provides a single point of access to it for any other code.
Singleton has almost the same pros and cons as global variables. Although they’re super-handy, they break the modularity of your code.
You can’t just use a class that depends on a Singleton in some other context, without carrying over the Singleton to the other context.
read morePosts
Prototype Pattern
Prototype is a creational design pattern that allows cloning objects, even complex ones, without coupling to their specific classes.
All prototype classes should have a common interface that makes it possible to copy objects even if their concrete classes are unknown. Prototype objects can produce full copies since objects of the same class can access each other’s private fields.
Golang Implementation Example: Let’s try to figure out the Prototype pattern using an example based on the operating system’s file system.
read morePosts
Chain Of Responsibility
Chain of Responsibility is behavioral design pattern that allows passing request along the chain of potential handlers until one of them handles request.
The pattern allows multiple objects to handle the request without coupling sender class to the concrete classes of the receivers. The chain can be composed dynamically at runtime with any handler that follows a standard handler interface.
Golang Implementation Example: Patient goes to hospital Let’s look at the Chain of Responsibility pattern with the case of a hospital app.
read more