3. 3
Name: Singleton
Intent: Ensure a class has only one instance and
provide a global point of access to it
Problem: How can we guarantee that one and only one
instance of a class can be created?
Solution: Define a class with a private constructor.
The class constructs a single instance of itself
Supply a static method that returns a reference to
the single instance.
6. 6
A status bar ….It could be implemented as a Singleton
object, allowing only one instance and a focal point for
updates.
One file system, one window manager, one printer
spooler, one Test engine, one Input/Output socket ,
Windows Registry etc.
13. Name: Observer
Intent: Define a one-to-many dependency between
objects so that when one object changes state, all its
dependents are notified and updated automatically.
Problem: You need to notify a varying list of objects
that an event has occurred.
Solution: delegate the responsibility for monitoring an
event to a central object.
13
14. Step 1: Make the Observers behave in the same way
Step 2: Have the observers register themselves
Step 3: Notify the observers when the event occurs
Step 4: Get the information from the observable
14
23. Suppose you are working on an MDI (Multiple
Documents Interface) Form that has several child.
You need to notify all the child about the changes
that occur in MDI form (e.g title changed).
Apply Observer pattern to solve this problem and
draw the corresponding class diagram.
23