 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chau Chee Yang Guest
|
Posted: Fri Jun 23, 2006 8:12 am Post subject: In MVP context, should Selection always a list type? |
|
|
Hi,
We learned from MVP that Model has a Selection, and Selection will bind
to Command. Command's execute will work on the binded Selection. An
Interactor will work on both View and Model, and Interactor will update
Model/Selection if user do changes from UI gestures.
The concept of Selection always implies that Selection is a List type
instance. However, not all model work with list. There are plenty of
model that work with single item instead of list. In this case, we may
argue that the single item may always add to the selection as the only
item in the selection and may access it via Selection.Items[0].
I have another thought regarding the selection:
If we model the selection as a generic item (say: IInterface), we may
then represent the selection by anything. It could be an item, a list
or anything that implement IInterface.
IModel = interface
[GUID]
...
function GetSelection: IInterface;
end;
Thus, if the model works on a list, then we can create a selection
object that may work with list. If the model work on a single item, we
may treat the item itself as selection and and eliminate the need to
access the item in Command.Execute via zero-based index as learned
previously:
procedure TCommand.Execute;
begin
...
(GetSelection as IItem)... // Old way: GetSelection.Items[0] as IItem
...
end;
Please comment. Thank you.
--
Best regards,
Chau Chee Yang
E Stream Software Sdn Bhd
URL: www.sql.com.my
SQL Financial Accounting |
|
| Back to top |
|
 |
Joanna Carter [TeamB] Guest
|
Posted: Fri Jun 23, 2006 1:58 pm Post subject: Re: In MVP context, should Selection always a list type? |
|
|
"Chau Chee Yang" <ccy (AT) sql (DOT) com.my> a écrit dans le message de news:
449b9899$1 (AT) newsgroups (DOT) borland.com...
| I have another thought regarding the selection:
|
| If we model the selection as a generic item (say: IInterface), we may
| then represent the selection by anything. It could be an item, a list
| or anything that implement IInterface.
|
| IModel = interface
| [GUID]
| ...
| function GetSelection: IInterface;
| end;
One problem with that approach : lack of type safety !!
Don't forget that for a single item model the selection could still be a
list. what if the model were a string that were being manipulated ? Then the
selection would be a list of characters ; or some other similar idea.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer |
|
| Back to top |
|
 |
Chau Chee Yang Guest
|
Posted: Fri Jun 23, 2006 2:17 pm Post subject: Re: In MVP context, should Selection always a list type? |
|
|
| Quote: | One problem with that approach : lack of type safety !!
Don't forget that for a single item model the selection could still be a
list. what if the model were a string that were being manipulated ? Then the
selection would be a list of characters ; or some other similar idea.
|
Even if we implement the selection as list approach, we also face the
lack of type safety problem too:
TStringSelection = class(TSelection)
Case 1: We have a TStringSelection to hold a list of chars
procedure TStringCommand.Execute;
begin
(GetSelection as IStringSelection).Items[0] ...
end;
The TStringCommand still cast the GetSelection to IStringSelection.
Case 2: Using a TSelection type that hold a list of chars
procedure TStringCommand.Execute;
begin
GetSelection.Items[0] as ICharItem
end;
It seems like both ways would need casting and that impose the lack of
type safety.
Unless TStringCommand has special BindSelection method:
TStringCommand = class
...
procedure BindSelection(const S: IStringSelection);
...
end;
But that would be hard to manage if each type of command would need to
write a special BindSelection method.
--
Best regards,
Chau Chee Yang
E Stream Software Sdn Bhd
URL: www.sql.com.my
SQL Financial Accounting |
|
| Back to top |
|
 |
Joanna Carter [TeamB] Guest
|
Posted: Fri Jun 23, 2006 3:20 pm Post subject: Re: In MVP context, should Selection always a list type? |
|
|
"Chau Chee Yang" <ccy (AT) sql (DOT) com.my> a écrit dans le message de news:
449bb1c2 (AT) newsgroups (DOT) borland.com...
| But that would be hard to manage if each type of command would need to
| write a special BindSelection method.
Which is why I used Delphi template classes in my implementation :
http://www.prototypical.co.uk/pdf/Templates.pdf
This then allows me to have a generic list functionality which is written
once and can be made typesafe with only a couple of lines of code.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer |
|
| Back to top |
|
 |
Chau Chee Yang Guest
|
Posted: Fri Jun 23, 2006 3:39 pm Post subject: Re: In MVP context, should Selection always a list type? |
|
|
Joanna Carter [TeamB] wrote:
| Quote: | "Chau Chee Yang" <ccy (AT) sql (DOT) com.my> a écrit dans le message de news:
449bb1c2 (AT) newsgroups (DOT) borland.com...
| But that would be hard to manage if each type of command would need to
| write a special BindSelection method.
Which is why I used Delphi template classes in my implementation :
http://www.prototypical.co.uk/pdf/Templates.pdf
This then allows me to have a generic list functionality which is written
once and can be made typesafe with only a couple of lines of code.
|
Cool. That's a brilliant ideas. However, I feel the template ways of
doing thing a bit weird. Does C# has something similar?
I feel perhaps I may choose the IInterface way for the Selection as it
is easy to coding.
--
Best regards,
Chau Chee Yang
E Stream Software Sdn Bhd
URL: www.sql.com.my
SQL Financial Accounting |
|
| Back to top |
|
 |
Joanna Carter [TeamB] Guest
|
Posted: Fri Jun 23, 2006 5:16 pm Post subject: Re: In MVP context, should Selection always a list type? |
|
|
"Chau Chee Yang" <ccy (AT) sql (DOT) com.my> a écrit dans le message de news:
449bc4c3$1 (AT) newsgroups (DOT) borland.com...
| Cool. That's a brilliant ideas. However, I feel the template ways of
| doing thing a bit weird.
Not at all. This is only a way of making up for a missing feature, soon to
be properly introduced in Delphi for .NET and, rumour has it, also in
Win32.
| Does C# has something similar?
Absolutely, C# 2.0 has generics, and just like the examples I have given,
you can use them for things other than just lists. At the moment, I have
nearly 50 custom generic classes, delegates, etc in my frameworks.
| I feel perhaps I may choose the IInterface way for the Selection as it
| is easy to coding.
Don't give in to the dark side Try the templates, they really work well
and, what is more, they even allow debugging through the code in the include
files.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer |
|
| Back to top |
|
 |
Chau Chee Yang Guest
|
Posted: Sat Jun 24, 2006 2:42 pm Post subject: Re: In MVP context, should Selection always a list type? |
|
|
| Quote: | Don't give in to the dark side Try the templates, they really work well
and, what is more, they even allow debugging through the code in the include
files.
|
I have read the template articles you sent to me and have tried to feel
how the templates works in Delphi.
I found there is one obvious restriction with template: A single pascal
unit can only contain one type of class that implement the template.
For example, if I have 2 list:
type
TMyThing = class
end;
_ITEM_CLASS = TMyThing;
{$I ObjectListTemplate.Intf}
TMyThingList = _LIST_CLASS;
type
TMyThing2 = class
end;
_ITEM_CLASS = TMyThing2;
{$I ObjectListTemplate.Intf}
TMyThing2List = _LIST_CLASS;
These 2 list must declare/define in different .pas unit else we will
encounter compiling error. The way of template implementation is using
file include method and doesn't work like a C++ template that works like
Macro.
With the introduction of $Region tag in new version of Delphi (BDS
2005/2006), it is easy to keep classes that has similar functionalities
in a same unit and use region to classified it. We may then enjoy the
the code folding in the new IDE editor.
Regardless of the one unit one class problem. Let's go back to MVP. I
re-study the possibility of using the MVP framework that implement the
template and found it isn't easy or almost impossible to implement with
template. For example, we have
ISelection = interface
end;
ICommand = interface
procedure BindSelection(const S: ISelection);
procedure Execute;
end;
ICommandSet = interface
property Items[Index: integer]: ICommand read GetItems;
end;
IModel = interface
property Selection: ISelection;
property CommandSet: ICommandSet
end;
IView = interface
end;
IPresenter = interface
property Model: IModel;
property View: IView;
end;
If we were to implement the selection with template in order to satisfy
the Strong Type design, does this implies that the Model and Command
should design with template? And in turns, the Presenter has to design
with template too?
If that is the case, then we will not have a common ICommand, IModel,
ISelection and etc. All we have in the source code would be
IxxxCommand, IxxxSelection, IxxxModel, ... and classes implement those
interfaces: TxxxCommand, TxxxSelection, TxxxModel... If this is the
case, then we have troubles to bind the Command to UI gesture. For
example, A TxxxCommand will have to write a TxxxButton class.
This is what I see the impact of implementing the template with MVP.
Perhaps there are something missing that I am not aware of.
--
Best regards,
Chau Chee Yang
E Stream Software Sdn Bhd
URL: www.sql.com.my
SQL Financial Accounting |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|