.NET design question

  • Thread starter Thread starter TomTom
  • Start date Start date
T

TomTom

Hi,

I am creating a simple .NET UI app and have a question on the way parameters
are passed between classes. Here is the situation.

1. I created a UI (Form1 class). This UI has many UI controls.
2. I created a separate class called MyClass.
3. MyClass needs to know what values are assigned in the UI controls in
Form1. The values are used in MyClass.

I can change the access modifier of the UI controls in Form1 from private to
public, but I assume this is not a good practice. Should I pass all the
values in Form1 to MyClass when it's constructed? Or is there a better
method?

Thanks!
 
TomTom,
Can you explain in a little more detail just what MyClass is used for
and what you are doing in the Form and the Class?
Thanks,
Patrick Altman
paltman@gmailJUST_SAY_NO_TO_SPAM.com
 
You might just want to use the public modifiers. But the best choice would
be to develop an object having the properties then use Eiffel (multiple
inheritance) to subclass your form on. Next best choice is to set that
object as a property of the form. The idea is to separate data from logic
so the Form should be assigning values, not the class. Another option for
you might be Reflection.
 
It's a file copy program. I have many checkboxes and radio buttons on Form1.
Actually I have a few classes (MyClass1, MyClass2, MyClass3, etc.) that need
to know the values set on the UI controls. The series of MyClass classes
define business rules of how the files are copied.
 
Two solutions

1. As you suggested you can pass the values of all controls to MyClass
when it is constructed. But if the number of values is too large then it
will become tedious.

2. Expose the values required by MyClass as public properties in MyForm,
the properties will retrieve the values of the controls when the get
method is called. This is the best solution in case the values change
after MyClass has been instantaniated.

For Example, if you have a FileOpenDialog, then you can declare a
property like

public string SelectedFileName
{
get
{
return fileOpenDialog.FileName;
}
}



Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Back
Top