Question that I have debated back and forth on

B

Bill Gower

I have a form that displays a list of items. The user can either click on a
button called "New" to create a new item or double click on a row in the
list to edit that item. An edit form is displayed for the add or edit and
the changes are made and then the user clicks on a save or cancel button to
close the form. Here is the question.
Who should create the object for the form to add to or edit?

Should the form with the list create an object and then pass the object to
the edit form or should the edit form create the object?

Who saves the object the edit form or the list fom when it is returned to?

Bill
 
P

Peter Duniho

Bill said:
I have a form that displays a list of items. The user can either click on a
button called "New" to create a new item or double click on a row in the
list to edit that item. An edit form is displayed for the add or edit and
the changes are made and then the user clicks on a save or cancel button to
close the form. Here is the question.
Who should create the object for the form to add to or edit?

Should the form with the list create an object and then pass the object to
the edit form or should the edit form create the object?

To some extent, I think the choice is arbitrary. Either should work
fine, and so it depends on which design just feels better to you.

That said, if you want the edit form to be identical for new and
existing objects, then you may not want to have to include logic for
dealing with object instantiation in the edit form. This would be an
argument in favor of having the object created before showing the edit
form, created by the list form.

Since you specifically write that "an edit form is displayed for the add
or edit", this seems to imply that the same form is used for both. In
that case, I would think that having the list form create the object and
then using the edit form to allow the user to customize the values for
the object would work better.
Who saves the object the edit form or the list fom when it is returned to?

Define "saves". Are you storing these objects to a database? Writing
them to a file? Or are you simply asking how the data from the edit
form should make its way back to the object itself?

IMHO, this is again a somewhat arbitrary decision. Even if you put
instantiation of the object in the list form, you can either have the
edit form operate on a specific instance of the object, or simply
present values that eventually are read by the list form to assign back
to the object being edited.

Note that all of the above assumes you're doing everything through
explicit code. I haven't done this myself, but I think that with data
binding you can have the edit form behavior in a more automatic way with
the object. If you take advantage of that, then the decision is made
for you, as the object needs to already exist for the edit form to have
its controls bound to the object's properties, and the controls of the
edit form itself will directly assign values to those properties.

Since your questions imply that the question is open, I'm assuming
you're not doing anything like that. :)

Pete
 
P

Peter Duniho

Peter said:
[...]
That said, if you want the edit form to be identical for new and
existing objects, then you may not want to have to include logic for
dealing with object instantiation in the edit form. This would be an
argument in favor of having the object created before showing the edit
form, created by the list form.

Since you specifically write that "an edit form is displayed for the add
or edit", this seems to imply that the same form is used for both. In
that case, I would think that having the list form create the object and
then using the edit form to allow the user to customize the values for
the object would work better.

And just to clarify: the above assumes that your edit form takes (in the
constructor or some initialization method) a reference to the object
being edited. Of course, if you simply initialize individual values in
the edit form and then read them after the form has been dismissed for
assignment back into the object, you could even defer creation of the
object until after you know for sure that the user has accepted rather
than canceled the edit form.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top