Design Patterns
Design Patterns
Design Patterns
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
REQUIREMENTS (2)<br />
• When the name of a file or directory is changed (setName), the<br />
representation of the name on the display will be updated, too.<br />
Applicability Use the Observer pattern when<br />
• change to one object requires changing others,<br />
and you do not know how many objects need to be changed.<br />
• an object should be able to notify other objects without making<br />
assumptions about who these objects are.<br />
45<br />
47<br />
EXAMPLE: “OBSERVER”<br />
Classification object/behavioral<br />
Intent Define a one-to-many dependency between objects so that when one<br />
object changes state, all its dependents are notified and updated<br />
automatically.<br />
Also Known As Dependents, Publish-Subscribe<br />
Structure<br />
Subject<br />
Attach(Observer)<br />
Detach(Observer)<br />
Notify()<br />
ConcreteSubject<br />
subjectState<br />
GetState()<br />
SetState()<br />
observers<br />
46<br />
48<br />
subject<br />
Observer<br />
Update()<br />
ConcreteObserver<br />
observerState<br />
Update()