Tuesday, August 23, 2005

Selection / Command / CommandSet

Newsgroups: borland.public.delphi.oodesign
From: "Joanna Carter \(TeamB\)"
Date: Wed, 26 Nov 2003 09:04:24 -0000
Local: Wed, Nov 26 2003 5:04 pm
Subject: Re: How to map self-induced model changes to a selection?


I think what is needed here is to use the Interactor to detect when an editing keystroke happens in the View and suspend the View's ability to update itself until the edit is complete. At which point the View would once again start reacting to updates in the Time model.

You might also want to consider splitting the concept of Time into Hours, Minutes and Seconds 'sub-models' and having the View also contain 'sub-views' ??

Newsgroups: borland.public.delphi.oodesign
From: "Joanna Carter \(TeamB\)"
Date: Wed, 26 Nov 2003 14:17:43 -0000
Local: Wed, Nov 26 2003 10:17 pm
Subject: Re: How to map self-induced model changes to a selection?


Then, because the Model has changed state, it has to inform the Command Set that it owns; just because the Command Set is an Observer of the Selection doesn't mean that other objects can't talk to it.

If you implement such Models as State Machines, then you can stop further changes to the Selection/Command Set happening.

Newsgroups: borland.public.delphi.oodesign
From: "Joanna Carter \(TeamB\)"
Date: Fri, 20 Feb 2004 09:58:09 -0000
Local: Fri, Feb 20 2004 5:58 pm
Subject: Re: MVP again - how to implement a view of a selection


You might consider using Aspects to enhance the behaviour of the Observer.

Here is a rough outline :

IAspect = interface
function CompareTo(const Other: IAspect);
funstion ToString: string;
end;

TSelectionAspect = class
class function Single: IAspect;
class function Multiple: IAspect;
class function Empty: IAspect;
end;

IAspectObserver = interface
procedure Update(const Subject: IInterface; const Aspect: IAspect);
end;

IAspectSubject = interface
procedure Attach(const Observer: IAspectObserver);
procedure Detach(const Observer: IAspectObserver);
procedure Notify(Subject: IInterface; const Aspect: IAspect);
end;

TMySelection = class
private
fSubject: IAspectSubject;
public
procedure AddItem(const Item: TMyClass);
procedure RemoveItem(const Item: TMyClass);
...
end;

procedure TMySelection.AddItem(const Item: TMyClass);
begin
fItems.Add(Item);
case fItems.Count of
0:
fSubject.Notify(nil, TSelectionAspect.Empty);
1:
fSubject.Notify(fItems[0], TSelectionAspect.Single);
else
fSubject.Notify(fItems, TSelectionAspect.Multiple);
end;
end;

procedure TMySelection.RemoveItem(const Item: TMyClass);
begin
fItems.Remove(Item);
DoNotify;
end;

TSelectionView = class
procedure Update(const Subject: IInterface; const Aspect: IAspect);
...
end;

procedure TSelectionView.Update(const Subject: IInterface; const Aspect:
IAspect);
// subject can be either a single object or a list
begin
// clear display
if Aspect.CompareTo(TSelectionAspect.Single) then
// display single object
else
if Aspect.CompareTo(TSelectionAspect.Multiple) then
// display list object
end;

Newsgroups: borland.public.delphi.oodesign
From: "Joanna Carter"
Date: Sat, 30 Aug 2003 08:46:35 +0100
Local: Sat, Aug 30 2003 3:46 pm
Subject: Re: Opinions wanted


There are times when you want to deal with a single object rather than a collection. There may be different rules that apply to a collection or an object.

For example, in the MVP framework we have the concepts of Selection and Command Set.

The Selection for a single object like a Customer can just be the single object that makes up the Model, but in the case of a Document, the Selection is going to be the currently selected text; but in the case of a collection of Documents, the Selection is going to be none, one or more documents.

The Command Set for a single object may be Edit, View, Save and Print, but the Command Set for a collection would typically include Add, Insert, Delete, Sort, Move, etc. Because a Command is executed against the Current Selection, each model can determine exactly what happens when that command is executed.

It is the purpose of the Model in MVP to provide support for validation that exceeds the boundary of the Value object that it is responsible for managing. Using MVP design patterns allows you to create generic editors for single objects and list presenters for collections.


Comments: Post a Comment

<< Home

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