Download presentation
Presentation is loading. Please wait.
1
E. Kraemer CSE 335: Software Design Administrivia Exam 2 : Wednesday, March 19 7-9pm Room: TBA Wed, March 12th - exam outline in class Mon, March 17th - practice exam in class
2
E. Kraemer CSE 335: Software Design Synthetic OO Design Concepts & Reuse Lecture 10: Mediators Topics: –Configuration/maintenance complexities that arise from collaboration synthesis –The mediator design pattern
3
E. Kraemer CSE 335: Software Design Recall from last time Synthesis: Construction of new, composite collaborations from simpler ones –E.g., adding a scrollbar to the collaboration between vp (a ViewPort) and dm (a DocManager) –Not automatable, but guided by heuristic methods May require new roles beyond those defined in the simpler collaborations E.g., vpm, which intercepts retrieve messages from vp and delegates them to dm with a line-number offset Today: Other design problems that require inventing new roles
4
E. Kraemer CSE 335: Software Design Example: A dialog box new century schoolbook Family Weight Slant Size avant garde century schoolbook courie r arial century gothic allegro amerigo CG Times Coronet Times Roman mediumbolddemibold roman italicoblique cancelok 34 pt The quick brown fox….. in sync font selection determines button settings
5
E. Kraemer CSE 335: Software Design Synchronization collaboration lb : ListBoxtb : TextBox announceNewSelection(id, item) Note: Assumes parameters to announceNewSelection identify the sender and the item that was selected. Question: What happens if selecting a new list item should also cause the greying of buttons? setValue(item)
6
E. Kraemer CSE 335: Software Design Problem Assembly from reusable collaborations can lead to tight coupling between application objects Bad because: –Complicates configuration –Distributes “invariant logic” among a large class of entities –Complicates collaboration synthesis, because we have to worry about update cycles
7
E. Kraemer CSE 335: Software Design Solution: Mediator Defn: Object that encapsulates how a set of objects interact [Gamma]. Advantages: –Promotes loose coupling by keeping objects from referring to one another explicitly. –Central point for resolving cyclic updates. –“Central manifestation” of invariant logic (as opposed to having logic distributed).
8
E. Kraemer CSE 335: Software Design Mediated vs. distributed collaboration Mediator ListBox TextBox ScrollBar Button ListBox TextBox ScrollBar Button
9
E. Kraemer CSE 335: Software Design Synch. collaboration (mediated) dir : Directorlb : ListBoxtb : TextBox announceNewSelection(id,item) setValue(…) userEvent() sd directed
10
E. Kraemer CSE 335: Software Design Mediator synthesizes listener roles class Director : public ButtonListener, public TextBoxListener, public ListBoxListener { public: Director(); virtual ~Director(); void buttonPressed( const string& ); void announceNewSelection( const string&, const string& ); void entryAction( const string& ); private: Button* ok; Button* cancel; ListBox* fontList; TextBox* fontName; }; Note: Message might come from ok or cancel Note: Message comes from fontList Note: Message comes from fontName
11
E. Kraemer CSE 335: Software Design Mediator localizes configuration code Director::Director() { ok = new Button(..., “OK”); cancel = new Button(..., “Cancel”); fontList = new ListBox(...); fontName = new TextBox(...); ok->registerListener(this); cancel->registerListener(this); fontList->registerListener(this); fontName->registerListener(this); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.