Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Mediator Matt G. Ellis. Overview ► Intent ► Motivation ► Mediators in GUI applications ► Mediators and Relational Integrity ► Conclusion ► Questions."— 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 TubMachine T305StarPress-2402 T308StarPress-2402 T377ShellAssembler-2301 T379ShellAssembler-2301 T389ShellAssembler-2301 T001Fuser-2102 T002Fuser-2102

12 ModelTubMachineT305StarPress-2402 T308StarPress-2402 T377ShellAssembler-2301 T379ShellAssembler-2301 T389ShellAssembler-2301 T001Fuser-2102 T002Fuser-2102

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

16

17 ► 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


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

Similar presentations


Ads by Google