From the course: Practical Design Patterns in Swift
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Broadcasting - Swift Tutorial
From the course: Practical Design Patterns in Swift
Broadcasting
- [Instructor] The observer design pattern allows a group of objects known as observers to get notified about state changes in another object, referred to as the subject. The observers register themselves with the subject. The subject updates all registered observers whenever its state changes. When an observer gets notified, it can retrieve the subject state it's interested in. This approach avoids the tight coupling between the observers and the subject. The observer pattern is implemented correctly if the subject interacts with the observers using a well-defined method, which is usually called notify. The method is defined in a common protocol, and all observers need to conform to that protocol. The subject only knows about the common protocol. No further implementation details are shared with the subject. Make sure that the observers get unregistered from the subject before releasing them. Otherwise, the subject keeps the reference to the observer instance that should have been…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.