1 / 24

Mediator

Mediator. Matt G. Ellis. Overview. Intent Motivation Mediators in GUI applications Mediators and Relational Integrity Conclusion Questions. Intent.

clairem
Télécharger la présentation

Mediator

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mediator Matt G. Ellis

  2. Overview • Intent • Motivation • Mediators in GUI applications • Mediators and Relational Integrity • Conclusion • Questions

  3. Intent • Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you very their interaction independently

  4. Motivation • Object Oriented design encourages distribution of behavior among objects • However, Good design is thwarted by every object referencing every other object • Changing systems behavior becomes difficult • Helps to prevent classes from becoming “thick”

  5. Mediator versus Façade • Façade pattern help refractor FlightPanel from Oozinoz • Refactoring can only go so far, complex applications still might need complex code even after applying Façade pattern

  6. Mediators at Oozinoz • Chemicals for fireworks kept in tubs • Robots move most of the tubs from machine to machine • However, humans can override the system

  7. FlightPanel_1 • Many methods exist to lazy-initialize variables • Rest control event handling logic

  8. Challenge 1 • Refactor PlaceATub_1 into two classes, introducing a new PlaceATubMediator that receives the events of the GUI

  9. Challenge 1 • Refactor PlaceATub_1 into two classes, introducing a new PlaceATubMediator that receives the events of the GUI

  10. Relational Integrity • If Object A points to Object B then… • Object B points to Object A • A more rigorous definition can be found in Metsker, page 108

  11. Relational Integrity and Java • Two Major Problems • Objects forget previous values • No built in support for Relational Integrity

  12. Model

  13. Challenge 2 • Suppose we have this code: //tell tub about machine, and machine about tub t.setMachine(m); m.addTub(t); • What happens when t is tub T308 and m is Fuser-2101?

  14. Challenge 2

  15. Challenge 2

  16. Challenge 2

  17. Challenge 2 • Really Bad Things… • Two machines think they have tub T308 in them • This can’t happen in the real world, why should it happen at Oozinoz? • Mediators can help

  18. Mediators for Relational Integrity • Pull all relational information into a mediator outside both classes • Have both tubs and machines have a reference to this mediator • Use a Map to store these key/value pairs

  19. Mediators for Relational Integrity • getMachine is simple, since t is the key of the map, HashMap makes it easy to get the value.

  20. Mediators for Relational Integrity • Somewhat more complex, but the intent is the same.

  21. Mediators for Relational Integrity • The most trivial method of all. Relational Integrity is maintained by the internal structure of the Map

  22. Challenge 3 • Write the code for the Tub methods: getMachine() and setMachine()

  23. Conclusions • Mediators provide loose coupling creating a “pluggable” system • Changing a mediator can change how applications deal with events • Mediators often found in GUIs • Swing’s event framework nudges the use of mediators, but they can be in the same class • Mediators also help to provide relational integrity between objects

  24. Questions

More Related