Here, the bus agency is the subject and all the passengers are the observers. If a bus gets delayed, then all the passengers who were supposed to travel in it get notified about the delay, to minimize inconvenience. In other words, the observer design pattern is employed when there is a one-to-many relationship between objects, such as when one object is updated, its dependent objects must be automatically notified. One could implement the observer design patterns when designing a system where several objects are interested in any possible modification to a specific object. When Will We Need Observer Design Pattern? Here the observers do not have any access to data, so they are dependent on the subject to feed them with information. This design pattern is also referred to as Dependents.Ī subject and observer(many) exist in a one-to-many relationship. The Observer Pattern maintains a one-to-many relationship among objects, ensuring that when the state of one object is changed, all of its dependent objects are simultaneously informed and updated. Observer design pattern falls under the category of behavioral design patterns.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |