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:
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:
- Constructing Presenter
- We may pass a Model and a View to Presenter. This is option as the Presenter may create the Model or View itself.
- Presenter attach View to Model via Observer pattern.
- When the Model value changed, it will notify View via Observer pattern.
- Selection may contain zero, one or many items in Model
- When Selection is updated, it will notify CommandSet via Observer pattern
- When CommandSet is notified, it will notify CommandMenu via Observer pattern. CommandMenu build Command from CommandSet.
- Create a CommandMenuItemVisitor. CommandSet accept the CommandMenuItemVisitor and deliver the Visitor to all Command item.
- Each Command will visit the Visitor.