Mediator Pattern


The Mediator pattern defines a separate object that encapsulates how two or more objects interact. This can break the coupling between them, making all the objects involved simpler and more clear.

Right now, the Form understands the mapping between the keyboard/ menu operations and the specific operations of the TextModel. For example, we have this code:

 if (kea.KeyCode == Keys.Enter && kea.Modifiers == Keys.None) { 
model.Enter();
kea.Handled = true;
}
else if (kea.KeyCode == Keys.Enter && kea.Modifiers == Keys.Shift) {
model.InsertReturn();
kea.Handled = true;
}

In the second of these cases, the Form knows that Shift+Enter means Insert Return. In the first of the cases, the Model is told Enter(), and it contains the code to decide what to do:

 public void Enter() { 
InsertParagraphTag();
}

I ve been concerned about this for a while. There has been discussion of which way is right, and we have an interaction with the Customer Acceptance Tests as well. We ve talked about that before. The Mediator pattern would allow me to break out the translation from form operations like keystrokes and menu actions into a separate class to encapsulate the idea. This could be really good.




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net