AlexLecture_Mediator

AlexLecture_Mediator - Mediator Pattern Alex X. Liu...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Mediator Pattern Alex X. Liu alexliu@cse.msu.edu http://www.cse.msu.edu/~alexliu 2132 Engineering Building Department of Computer Science and Engineering Michigan State University Review: Simple Collaboration Button (print), DocManager Goal: pressing button can invoke the print function of DocManager Define a new abstract class called ButtonListener . It has a pure virtual function Define a new class called MyDocManager : MyDocManager inherits from both ButtonListener and DocManager . Implements buttonPressed( const string& buttonLabel ) function , in which the print function of the DocManager is called. Change Button class as follows: Add a new data member – ButtonListener* listener (Be a vector if a button has multiple listeners.) 2 Alex X. Liu Add a new function – setListener(ButtonListener* l) {listener = l;} Client code: Button printButton(“print”); MyDocManager docMgr(…); printButton.setListener(& docMgr);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 More Collaborations – Synthesis sb vp vpm dm : ViewPort : ViewPortModel : ScrollBar : ValuatorListener : ValuatorListener 1: announceNewValue(X) 2: announceNewValue(X) 3: retrieve(index, string) 3 : DocManager 4: getLine(index+X, string) Even More Collaborations: Too Complex new century schoolbook Family The quick brown fox…. . avant garde century schoolbook courie r arial century gothic allegro amerigo CG Times Coronet Times Roman in sync font selection determines Weight and Slant settings 4 Alex X. Liu Weight Slant Size medium bold demibold roman italic oblique cancel ok 34 pt
Background image of page 2
3 Problems: Tight Coupling Distributing system behavior among objects generally enhances reusability. But, too many interconnections reduces reusability again.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

AlexLecture_Mediator - Mediator Pattern Alex X. Liu...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online