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.
Code Example: