1 / 10

Cam Quach Joel Derstine

Mediator: Object Behavioral. Cam Quach Joel Derstine. Intent. Mediator is an object to coordinate state changes between other objects Mediator promotes loose coupling by preventing objects from referring to each other explicitly

hisoki
Download Presentation

Cam Quach Joel Derstine

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: Object Behavioral Cam Quach Joel Derstine

  2. Intent • Mediatoris an object to coordinate state changes between other objects • Mediator promotes loose coupling by preventing objects from referring to each other explicitly • Mediator allows designers to vary their interactions independently

  3. Problem • Goal in OO design is to distribute behavior among objects • Distribution will increase reusability  # of objects  interconnections  reusability  reusability

  4. Solutions mediator Mediator Colleague ConcreteMediator ConcreteColleague1 ConcreteColleague2 • Structure • Mediator provides an interface for communicating with Colleague objects • ConcreteMediatorimplements a cooperative behavior by coordinating the Colleague objects • Colleaguessend and receive requests from a Mediator object

  5. A Conceptual Example: The Problem • Multiple aircraft in the air space of an airport need to communicate with each other about changes in (some of) their properties (speed, altitude, direction). • Where do the complexities reside if they tried to do this by communicating with each other directly? Duell, “Non-software examples of software design patterns”, Object Magazine, July 1997

  6. A Conceptual Example: The Problem Some complexities? • Who do they need to contact • When (or how often) do they need to contact • What do they need to tell them I’m landing! ? Not yet! I’m still taking off!! Duell, “Non-software examples of software design patterns”, Object Magazine, July 1997

  7. A Conceptual Example: A Solution A Control Tower (the “mediator”)! Manages the complexity of communications: • Who to contact (observer object?) • When to contact • What to say ? Duell, “Non-software examples of software design patterns”, Object Magazine, July 1997

  8. A Technical Example: The Problem Some issues/questions: • How should the widgets on this dialog box communicate? • What are the dependencies? • Each widget knows how to do its job. But should it know how it fits into the larger picture? GOF, “Design Patterns”, 1995

  9. A Technical Example: A Solution Create a FontDialogDirector Mediator! • Knows the widgets in the dialog box • Serves as the intermediary (widgets only know about the mediator). • Coordinates their interaction DialogDirector ShowDialog() CreateWidgets() WidgetChanged(Widget) director Widget Changed() FontDialogDirector CreateWidgets() WidgetChanged(Widget) ListBox GetSelection() list EntryField SetText() field GOF, “Design Patterns”, 1995

  10. Consequences Mediator • Limits subclassing • Decouples colleagues • Simplifies object protocols • Abstracts how objects cooperate • Centralizes control

More Related