Thursday, August 25, 2005

MVP Notes

Prenseter = Model + View + Command + CommandSet + Selection + Interactor

Model is Subject of View in general

View is Observer to Model

Selection is Visited (Visitor element in GOF Visitor pattern catalog)

Selection know Model: This is optional

Command bind Selection: To perform action on the selection's item.

Command is Visited: Used by ICommandVisitor.VisitCommand. Examples of some ICommandVisitor implementation are MenuItem, Button, any control that want to wired up with the command. The CommandSet will deliver the Visitor to the Command:

procedure TCommandSet.Accept(const Visitor: IVisitor);
var
i: Integer;
begin
for i := 0 to Pred(fItems.Count) do
(fItems[i] as IVisited).Accept(Visitor);
end;

procedure TCommand.Accept(const Visitor: IVisitor);
begin
(Visitor as ICommandVisitor).VisitCommand(self);
end;


CommandSet is a collection of Command

CommandSet is Observer of Selection: any change of Selection will notify CommandSet.

CommandSet is Subject. Some example of CommandSet observer are Command Menu, Pop up menu, SpeedButton Set or a set of UI controls that bind to CommandSet.

CommandSet is Visited: Act is a proxy visitor to deliver the Visitor to each Command item.

----------------------------------------
Presenter:

  1. Constructing Presenter
  2. We may pass a Model and a View to Presenter. This is option as the Presenter may create the Model or View itself.
  3. Presenter attach View to Model via Observer pattern.
Model:
  1. When the Model value changed, it will notify View via Observer pattern.
View:

Selection:
  1. Selection may contain zero, one or many items in Model
  2. When Selection is updated, it will notify CommandSet via Observer pattern
CommandSet:
  1. When CommandSet is notified, it will notify CommandMenu via Observer pattern. CommandMenu build Command from CommandSet.
  2. Create a CommandMenuItemVisitor. CommandSet accept the CommandMenuItemVisitor and deliver the Visitor to all Command item.
  3. Each Command will visit the Visitor.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?