Skip to content

Commit c9ede76

Browse files
committed
Observer definition and applicability
1 parent bc968e0 commit c9ede76

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ Use the Chain of Responsibility pattern when
6666
* A class can't anticipate the class of object it must create.
6767
* A class wants its subclasses to specify the objects it creates.
6868
* Classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclasses is the delegate.
69+
70+
#### 7.Observer
71+
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. It's also known dependents, pub-sub. [example](https://github.com/hbrawnak/php-design-pattern/blob/master/Observer/index.php#L3)
72+
73+
##### Applicability:
74+
Use the Observer pattern when
75+
* An abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently.
76+
* A change to one object requires changing others, and you don't know how many objects need to be changed.
77+
* An object should be able to notify other objects without making assumptions about who these objects are. In other words, you don't want these objects tightly coupled.
6978

7079
--------
7180
Sources:

0 commit comments

Comments
 (0)