BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Validate data between Model and Controller in MVC

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
MyiSeries
Guest





PostPosted: Thu Jan 20, 2005 11:16 am    Post subject: Validate data between Model and Controller in MVC Reply with quote



Hi,
I'm writing a businness application. Now I'm developing a common structure
to let users to manage custmers, suppliers and others correlated tables.
In other words I'm writing data-entry programs.

I don't understand what's the right way to validating data inserted by users.

Is there any sample project with source using MVC?
I've founded trivial samples, only.


thanks
Remo Candeli



--- posted by geoForum on http://delphi.newswhat.com
Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Thu Jan 20, 2005 4:09 pm    Post subject: Re: Validate data between Model and Controller in MVC Reply with quote



"MyiSeries" <r.candeliNOSPAM (AT) grandiorizzonti (DOT) com> a écrit dans le message de
news: [email]41efa09a (AT) newsgroups (DOT) borland.com[/email]...

Quote:
I'm writing a businness application. Now I'm developing a common structure
to let users to manage custmers, suppliers and others correlated tables.
In other words I'm writing data-entry programs.

Have a look at the articles on OPF on my site for waysof separating data
storage from object model.

Quote:
I don't understand what's the right way to validating data inserted by
users.


Validation can be done in the Model of MVP.

Quote:
Is there any sample project with source using MVC?
I've founded trivial samples, only.

Have a look at the articles on MVP on my website www.Carterconsulting.org.uk

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
MyiSeries
Guest





PostPosted: Mon Jan 24, 2005 9:00 am    Post subject: Re: Validate data between Model and Controller in MVC Reply with quote



Hi, thanks for reply

Quote:
Validation can be done in the Model of MVP.
Yes, I know that. But my question is:

When the model knows there is a sintax error (say: "customer code is
already inserted in the custmer table") it has to send message to the
controller to tell to it: "Hey, bad code!".
Well, does the Controller has to ask the question: "Model, check this code"?
Or maybe, the Model has to 'Notify' (implementing Observer pattern) state
changes? In this way I think I've got to create a customized protocol to
exchange messages between Model and Controller.


Quote:
Have a look at the articles on MVP on my website ww.Carterconsulting.org.uk
I've looked at you articles. I've founded very interesting and more

sophisticated, too. But, as a first step, I'm trying to write code following
the MVC using less code than the MVP.

Sorry for my english.
Hope you understand.



--- posted by geoForum on http://delphi.newswhat.com

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Mon Jan 24, 2005 5:12 pm    Post subject: Re: Validate data between Model and Controller in MVC Reply with quote

"MyiSeries" <r.candeliNOSPAM (AT) grandiorizzonti (DOT) com> a écrit dans le message de
news: [email]41f4c692 (AT) newsgroups (DOT) borland.com[/email]...

Quote:
Validation can be done in the Model of MVP.
Yes, I know that. But my question is:
When the model knows there is a sintax error (say: "customer code is
already inserted in the custmer table") it has to send message to the
controller to tell to it: "Hey, bad code!".
Well, does the Controller has to ask the question: "Model, check this
code"?
Or maybe, the Model has to 'Notify' (implementing Observer pattern) state
changes? In this way I think I've got to create a customized protocol to
exchange messages between Model and Controller.

I believe the best way to handle these situations is to do any setting of
values in the Model within a try..except block. This way the Controller
simply tries to set the value and catches any exception, feeding back the
result of the exception to the View or to another 'sub-view' that displays
the error, possiblt resetting focus to the offending edit.

Quote:
I've looked at you articles. I've founded very interesting and more
sophisticated, too. But, as a first step, I'm trying to write code
following
the MVC using less code than the MVP.

The real difference between MVC and MVP is that the 'message flow' is
handled via two different 'channels', one for each direction.

The user makes a Gesture in the View

An Interactor responds to that Gesture (that Interactor may delegate
reponsibility to nested Interactors, dependent on the complexity of the
Gesture).

If that Gesture is intended to alter the visual selection in the View, the
Interactor notifies the Selection in the Model.

Changes to the Selection are observed but he View and it is updated to
match.

The Selection then notifies any Observers, one of which will be the View
which will update itself accordingly, the other is the Command Set.

The Command Set updates itself based on the Selection to accomodate things
like Commands not being available when more than one/only one item are/is
selected.

Assuming that the Selection is now up to date, the Interactor translates
subsequent Gestures, determines which Command on the Model is to be called
and calls this Command.

Commands can be undone and redone and can alos support the concept of a
history if required.

If executing the Command raises an exception, then the Interactor is
responsible for creating a Presenter for that exception and directing the UI
to a suitable focus point.

Assuming the Command succeeds, the Model, which contains the Value Type is
passes the change to the Value Type.

The Value Type responds to the change by notifying any Observers, one of
which would be the View.

This structure is more flexible in that Interactors and Commands can be
relatively freely substituted depending on the nature of either the View or
the Model.

MVPs can also be nested, so you get a MVP 'component' for a BO, the View of
which will be a form, but this component will contain other MVP components,
one for each of the properties of the BO, the views of which will be the
edits on the form.

The inner MVP components can be created at runtime based on the names of the
BO properties matching the 'PropertyName' of the relevant edit on the form.

I tend to talk about creating Presenters for Value Types; this then means
that your client code usually creates/retrieves a Value Type (a BO is a
composite Value Type) and then simply passes that Value Type to the
constructor of a Presenter. The Presenter is responsible for creating a form
or other display and will self-destruct when the form closes.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.