When You Wash Your Hair

A Mantra for Healing

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Observer Design Pattern

Observer pattern deals in communication between objects. It defines a one-to-many relationship, when an object changes state it notifies a list of objects. Observer pattern is classified as the behavioral design pattern. It ultimately helps decouple senders and receivers.

Radio station can be an example for this pattern, as we all know it broadcasts music to all it’s listeners. As long as listeners are interested (or rather driving car) they listen to radio and before they are off to work, they turn it off and no longer receives the broadcast but radio station doesn’t stop broadcasting so, whenever listeners are interested they can join in.

Let’s see an Example:

Apple platform have a similar component called NSNotificationCenter in Swift it is NotificationCenter. We can use NotificationCenter to send and receive notifications.

Pros:

— Makes Sender and Listeners loosely coupled

Sender and Listeners are independent of each other, therefore, changes will not affect each other.

Cons:

— If misused, it can add complexity and lead to performance issues, like not unsubscribing even when listener is not listening.

Add a comment

Related posts:

Things To Know International Trademark Registration

The Indian and the International Trademarks, both have different registration procedures and provide different benefits to a company. As the name suggests one protects the products and services at a…

The American law of the Vietnam War

For proving is 1 U.S.C. § 112 [20] — U.S. Code — Unannotated Title 1. General Provisions § 112. Statutes at Large; contents; admissibility in evidence Search U.S. Code ________________ [20] Text from…

Introducing DumDarac Breathing

A simple and intuitive application that will soon integrate new functionalities such as listening to relaxing background music, meditation exercises, finding other users who like this lifestyle, etc…