On Mon, 14 May 2007 00:24:33 -0700, Christof Nordiek <cn@nospam.dewrote:
Surely you can implement it in that way. But there are fundamental
reason, why you shouldn't.
First: Making the field public, allows other classes not only to access
the control, but even to assign another control to that variable.
Second and more important: The PreferenceForm has to know, where to store
the results in its calling form. This strongly reduces the reusability of
that form and the maintainability of the code.
Note that when I wrote that statement, I was under the incorrect
impression that the "private CustomClass" was a class declaration rather
than a field declaration. I have no good explanation for why I misread
the code in such an obviously wrong way. But I did. :)
I certainly agree that a field should not be public, as well as with most
of the rest of what you wrote. I agree that the PreferenceForm should not
be strongly tied to the calling form's class.
That said, to some extent a "preferences" dialog form is always going to
be custom to at least some class of forms, if not to a specific form. So
while I agree that fields shouldn't be made public, I don't think it's
terrible for the PreferenceForm to have *some* knowledge of the calling
form (such as using a specific shared class to communicate the data). As
an example, one idea I've been kicking around is having the PreferenceForm
public an interface that the calling form is required to implement, and
which the calling form passes to the PreferenceForm.
I don't have any great reasons for thinking this is better than having the
data flow the other direction (it has the "preferences" dialog manage the
data flow, while the alternative has the calling form manage the data
flow), but I also don't have any great reasons for thinking it's worse in
any way. One way or the other, the calling form has to implement some
sort of "glue" to connect to the "preferences" dialog form, so it seems to
me that whether it implements an interface or accesses properties on the
dialog form or whatever, it's all the same in the end. :)
Pete