Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I provide accessor methods / Getter Setters for public/protected components on a form?

Tags:

.net

winforms

If I have .Net Form with a component/object such as a textbox that I need to access from a parent or other form I obviously need to "upgrade" the modifier to this component to an Internal or Public level variable.

Now, if I were providing a public variable of an int or string type etc. in my form class I wouldn't think twice about using Getters and (maybe) Setters around this, even if they didn't do anything other than provide direct access to the variable.

However, the VS designer doesn't seem to implement such Getters/Setters for those public objects that are components on a form (and therefore does not comply with good programming practice).

So, the question is; In order to do the "right thing" should I wrap such VS designer components or objects in a Getter and/or Setter?

like image 995
Calanus Avatar asked Aug 08 '08 14:08

Calanus


1 Answers

"However, the VS designer doesn't seem to implement such Getters/Setters for those public objects that are components on a form (and therefore does not comply with good programming practice)."

If you mean the controls you're dragging and dropping onto the form, these are marked as private instance members and are added to the form's Controls collection. Why would they be otherwise? A form could have forty or fifty controls, it'd be somewhat unnecessary and unwieldy to provide a getter/setter for every control on the form. The designer leaves it up to you to provide delegated access to specific controls via public getter/setters.

The designer does the right thing here.

like image 197
Kev Avatar answered Oct 21 '22 02:10

Kev