Behavioural Design Patterns In Golang
This post will look at some of the most commonly used Behaviour Design Patterns, including Command, Chain Of Responsibility, State, Observer, Memento, Iterator, Interpreter, Strategy, Visitor, Template, and Mediator.

Behavioural design patterns are concerned with algorithms and the assignment of responsibilities between objects. These patterns concern the communication between objects and how they operate. They define the ways objects interact and communicate with each other. Behavioural Design Patterns include Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Visitor, Memento, Strategy, and so on.
- The Strategy pattern is a behavioural design pattern that allows you to define a family of algorithms and dynamically switch between them at runtime. Strategy lets the algorithm vary independently of clients that use it. The Strategy pattern is probably the easiest to understand of the Behavioral patterns. For more details please click here
- The Chain of Responsibility pattern is a behavioural design pattern that allows multiple objects to handle a request, with each object having the opportunity to either handle the request or pass it along to the next object in the chain. The objects in the chain are not aware of each other but instead communicate through a common interface, allowing new objects to be added or removed from the chain easily. For more details please click here
- The Command pattern is a behavioural design pattern that allows encapsulating a request or operation as an object. It converts requests or simple operations into a stand-alone object that can be stored, passed, and executed independently of the original requester. The pattern separates the requester (client) from the object that acts (receiver). This transformation lets you pass requests as method arguments, delay or queue a request’s execution, and support undoable operations. For more details please click here
- The Template pattern is a behavioural design pattern that defines the skeleton of an algorithm in a base class and allows subclasses to override some steps of the algorithm without changing its structure. In other words, it provides a way to define the steps of an algorithm, while allowing subclasses to implement specific behaviours that can vary. For more details please click here
- The Memento pattern is a behavioural design pattern that allows an object to save its internal state so that it can be restored later, without violating encapsulation. In other words, it provides a way to capture the current state of an object and restore it to that state later on. For more details please click here
- The Iterator pattern is a behavioural design pattern that provides a way to traverse a collection of objects without exposing the underlying implementation details. It allows you to access the elements of a collection sequentially, one at a time, without having to know the internal structure of the collection. For more details please click here
- The Interpreter pattern is a behavioural design pattern that is widely used to solve business cases where it’s useful to have a language to perform common operations. The pattern involves creating a set of algorithm classes for solving logical puzzles. For more details please click here
- The Visitor pattern is a behavioural design pattern that allows you to add new algorithms from the structure of the objects on which they operate. It involves defining a separate object (the visitor) that can visit each object in a complex structure and perform some operation on it. This way, you can modify the behaviour of a group of objects without changing their classes. For more details please click here
- The State pattern is a behavioural design pattern that allows an object to change its behaviour based on its internal state. It allows an object to change its behaviour without changing its class, by delegating behaviour responsibility to different state objects. The State pattern promotes loose coupling, high cohesion, and easy maintenance of the codebase. For more details please click here
- The Mediator pattern is a behavioural design pattern that allows communication between different objects through a central object called the Mediator. This pattern reduces coupling between objects by making objects communicate indirectly. The Mediator object encapsulates the communication logic between objects and acts as an intermediary to coordinate their interactions. For more details please click here
- The Observer pattern is a behavioural design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing. That means the observer pattern allows some objects to notify other objects about changes in their state. It is also known as publisher/subscriber or publish/listener design pattern. For more details please click here
Conclusion
Behavioural patterns focus on how objects interact with one another and how they can communicate and collaborate. They help developers create effective, flexible, and maintainable code that can adapt to changes in business requirements. Examples of behavioural patterns include the Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template, and Visitor patterns.
These pattern categories can provide developers with a set of proven solutions to common software design problems, enabling them to create high-quality, maintainable, and scalable code that can adapt to changing requirements over time.
Click here to go back to Design Patterns in Golang
To view Creational Design Patterns in Golang, please click here.
To View Structural Design Patterns in Golang, please click here.
To View Behavioural Design Patterns in Golang, please click here.
To View Concurrency Design Patterns in Golang, please click here.
To View Microservices Design Patterns in Golang, please click here.






