Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oct 200291.3913 R McFadyen1 Facade P. 368+ Problem: There are a set of classes, a subsystem, that you need to interact with for some purpose, but you don’t.

Similar presentations


Presentation on theme: "Oct 200291.3913 R McFadyen1 Facade P. 368+ Problem: There are a set of classes, a subsystem, that you need to interact with for some purpose, but you don’t."— Presentation transcript:

1 Oct 200291.3913 R McFadyen1 Facade P. 368+ 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

2 Oct 200291.3913 R McFadyen2 Facade :ClassX:Facade msg2 (…) msg1()......

3 Oct 200291.3913 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.

4 Oct 200291.3913 R McFadyen4 Observer P. 368+ 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

5 Oct 200291.3913 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.

6 Oct 200291.3913 R McFadyen6 Figure 23.20 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

7 Oct 200291.3913 R McFadyen7 Figure 23.21 The Observer Pattern in a DCD

8 Oct 200291.3913 R McFadyen8 Figure 23.21 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

9 Oct 200291.3913 R McFadyen9 Figure 23.21 The Observer Pattern in a DCD Note: A Sale will know when it has changed, and that it must notify its observers

10 Oct 200291.3913 R McFadyen10 Figure 23.21 The Observer Pattern in a DCD Note: A Sale will send messages to its many observers

11 Oct 200291.3913 R McFadyen11 Figure 23.22 a window subscribing When a SaleFrame1 (the subscriber) is initialized, it subscribes to the Sale (the publisher)

12 Oct 200291.3913 R McFadyen12 Figure 23.23 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

13 Oct 200291.3913 R McFadyen13 Figure 23.24 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


Download ppt "Oct 200291.3913 R McFadyen1 Facade P. 368+ Problem: There are a set of classes, a subsystem, that you need to interact with for some purpose, but you don’t."

Similar presentations


Ads by Google