Design Patterns in GO — Behavioral Patterns (Part 2)

Loc Ngo
3 min readOct 2, 2022

This part is the second part of Behavioral Design Pattern (first part is here), and it is also the last part of series Design Patterns in GO. In this article, we are going to walk through 5 remaining types of behavioral design patterns. They are:

Observer is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. The observer pattern is also known as Dependents or Publish-Subscribe. It addresses following problems:

  • A one-to-many dependency between objects should be defined without making the objects tightly coupled.
  • It should be ensured that when one object changes state, an open-ended number of dependent objects are updated automatically.
  • It should be possible that one object can notify an open-ended number of other objects.
UML Class Diagram

Code Example:

--

--

Loc Ngo
Loc Ngo

Written by Loc Ngo

Software Architect at Fortna and a passionate software developer