Chapter 10 Mediator. Summary prepared by Kirk Scott. Athena From Wikipedia, the free encyclopedia.
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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Summary prepared by Kirk Scott
In Greek religion and mythology, Athena or Athene (pron.: /əˈθiːnə/ or /əˈθiːniː/; Attic: Ἀθηνᾶ, Athēnā or Ἀθηναία, Athēnaia; Epic: Ἀθηναίη, Athēnaiē; Ionic: Ἀθήνη, Athēnē; Doric: Ἀθάνα, Athānā), also referred to as Pallas Athena/Athene (pron.: /ˈpæləs/; Παλλὰς Ἀθηνᾶ; Παλλὰς Ἀθήνη), is the goddess of wisdom, courage, inspiration, civilization, law and justice, just warfare, mathematics, strength, strategy, the arts, crafts, and skill. Minerva is the Roman goddessidentified with Athena.
Athena is also a shrewd companion of heroes and is the goddess of heroic endeavour. She is the virgin patroness of Athens. The Athenians founded the Parthenon on the Acropolis of her namesake city, Athens (Athena Parthenos), in her honour.
Summary prepared by Kirk Scott
The implementation of mediators can differ depending on what the relationships between instances of the base classes are
The background for mediators can be expressed in terms of responsibility
The Mediator pattern can be viewed as offloading/concentrating responsibility/functionality into a separate class
Although conceptual in nature, the relationships are real aspects of the design
Also note that the set of relationships itself becomes an abstraction that might be implemented as a separate class
The individual objects become dependent on the class that maintains the relationships
In order to reduce the “voila” factor, it is helpful to give a preview of how it will fit together:
In other words, analytically speaking, in an MVC design, the controller serves as a mediator between the model and the view
Overall in this example a relationship between the data model and the graphical user interface representation of the state of the application has to be maintained
It is important to understand that at this point the book is interested in mediation between the graphical user interface and the data model in the application
Once three things are highlighted in the interface, you can press the “Do it!” button
Using a wizard might produce a class named MoveATub that is basically a monolithic application
The book observes that at the very least you might consider moving the event handling methods into a different class
What we’ve just seen in the monolithic MoveATub class is that the class itself can implement the listening interface
Where to put listening and how to make sure listeners have access to the things they need are important topics in Java GUI programming
MoveATubMediator implements the ActionListener and ListSelectionListenerinterfaces, suggesting it’s a controller
It is also possible for the mediator to take actions on the GUI, like enabling or disabling a button
A simplified, generic UML diagram of the pattern would show the button and the NameBase, with the MoveATubMediator between them.
Just looking at the book’s UML diagram, some of the relationships and arrows are not completely clear
It may or may not be good that the authors haven’t done a full MVC design
The book is going to pursue the idea of relationships using the machines and tubs of Oozinoz
For the purposes of that example, the machines and tubs, or lists of machines and tubs, were simply relegated to that part of the design having to do with the business model
There is no automatic support in programming languages like Java for concepts like enforcing a one-to-many relationship
The book illustrates the pitfalls of trying to maintain relationships with an example
They will have their relationships captured in the mediator/table
The Tub and Machine classes have methods for adding a tub to a machine, assigning a machine to a tub, etc.
On the following two overheads is detailed material from the Java API on the hash table get() and put() methods
The way to envision the use of the hash table with tubs and machines is this:
Note that the implementations of the getTubs() and set() methods are quite simple
This is not the end of the book’s code, just a brief interruption
The Tub class needs hashCode() and equals() methods for the following reason:
Functionally, the setLocation() and getLocation() methods of the Tub class wrap calls of this kind on the mediator:
Functionally, the set() and getMachine() methods of the TubMediator class wrap calls of this kind on the hash table, where the parameter t is the tub (this) of the wrapping call:
In short, the tubs are being passed in as the key values for the hash table
The only lingering question is why the authors chose to implement hashCode() and equals() on the basis of a tub’s id rather that on the basis of the tub object itself
The one concrete consequence of the decision that I can see is that it will ultimately force the user to make sure that tub id’s are unique
You might also argue that the relationships possible between classes are intrinsic parts of the definitions of the classes
A UML diagram for the application is given on the overhead following the next one.
Not a lot of care is taken in the implementation of CupsAndSeedsDB, so it isn’t a full scale example of a mediator
/* The idea behind this class is that each seed will be of a different color.
In the UML diagram for the textbook’s second example, with the namebase, you see this:
Which of these options is correct—which things in the design should have references to which other things?
2. The following overhead summarizes Lasater’s example, with references from the mediator to the base class objects
3. The following overhead shows an example with references in both directions
Depending on how the code is structured, it may be necessary for the base class objects to have references to their mediator
Whenever it may be desirable to implement the interactions between objects in a separate class, the Mediator pattern applies