Oct R McFadyen1 Facade P Problem: There are a set of classes, a subsystem, that you need to interact with for some purpose, but you don’t want to create dependencies on this subsystem. Solution: Create a class that wraps this subsystem. The wrapper will define an interface that hides the details (classes, methods) of the subsystem. The façade is a “front-end” object that defines a single point of entry to the subsystem’s services. Showing the classes as a package (a subsytem) A façade, a wrapper
Oct R McFadyen2 Facade :ClassX:Facade msg2 (…) msg1()......
Oct R McFadyen3 To create a simpler interface: number of methods, number of objects one has to deal with All requests to go through a Façade class, one can easily track usage To facilitate subsystem replacement – only one class is affected, the Façade class. This is the motivation in Larman’s example.
Oct R McFadyen4 Observer P Also known as Publish-Subscribe Applied in order to implement the Model-View Separation principle (see pages 471+) model and view are separated non-GUI objects are not directly coupled to GUI components domain objects are not directly coupled to window objects same as Model-View-Controller (MVC) principle that came from Smalltalk
Oct R McFadyen5 Observer Problem: There are many objects (subscribers) needing to know of the state changes, or events, of another object (publisher), and we want to keep the coupling low. Solution: Define a subscriber or listener interface that is implemented by the subscribers.
Oct R McFadyen6 Figure the display must reflect the correct total There is a requirement for a window to be updated whenever the total value of the sale changes
Oct R McFadyen7 Figure The Observer Pattern in a DCD
Oct R McFadyen8 Figure The Observer Pattern in a DCD Note: SaleFrame1 is-a Jframe SaleFrame1 implements the PropertyListener interface – it has an update method (onPropertyEvent) Note: Since a SaleFrame1 sends the add msg, there is a dependency of SaleFrame1 on Sale
Oct R McFadyen9 Figure The Observer Pattern in a DCD Note: A Sale will know when it has changed, and that it must notify its observers
Oct R McFadyen10 Figure The Observer Pattern in a DCD Note: A Sale will send messages to its many observers
Oct R McFadyen11 Figure a window subscribing When a SaleFrame1 (the subscriber) is initialized, it subscribes to the Sale (the publisher)
Oct R McFadyen12 Figure a sale publishing a change A Sale receives a message changing its state. The Sale invokes its method, publishPropertyEvent, which will in turn notify any subscribers of the change Note the activations for the sale
Oct R McFadyen13 Figure a window receiving notification The window receives notification of the state change and modifies its display appropriately Notice that this is a continuation from the previous sequence diagram