<p>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.</p>

<p>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.</p>

<p>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).</p>

<p>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?</p>

[{'answer_id': 6003, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 1, 'selected': False, 'text': '<p>I always do that, and if you ARE following an MVP design creating getter/setters for your view components would be a design requirement.</p>\n\n<p>I do not understand what you mean by "does not comply with good programming practice". Microsoft violates <em>a lot</em> of good programming practices to make it easier to create stuff on Visual Studio (for the sake of rapid app development) and I do not see the lack of getters/setters for controls as evidence of violating any such best practices.</p>\n'}, {'answer_id': 6005, 'author': 'Tanerax', 'author_id': 567, 'author_profile': 'https://Stackoverflow.com/users/567', 'pm_score': 2, 'selected': False, 'text': "<p>The reason for not implementing Getters and Setters for components on a form I believe is cause they wouldn't be &quot;Thread Safe&quot; .NET objects are suppose to be only modified by the form thread that created them, If you put on getter and setters you are potentially opening it up for any thread. Instead your suppose to implement a delegate system where changes to these objects are delegated to the thread that created them and ran there.</p>\n"}, {'answer_id': 6018, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 4, 'selected': True, 'text': '<p>"<em>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).</em>"</p>\n\n<p>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.</p>\n\n<p>The designer does the right thing here.</p>\n'}, {'answer_id': 6095, 'author': 'Simon Gillbee', 'author_id': 756, 'author_profile': 'https://Stackoverflow.com/users/756', 'pm_score': 2, 'selected': False, 'text': "<p>This is a classic example of encapsulation in object-oriented design.</p>\n\n<p>A Form is an object whose responsibility is to present UI to the user and accept input. The interface between the Form object and other areas of the code should be a data-oriented interface, not an interface which exposes the inner implementation details of the Form. The inner workings of the Form (ie, the controls) should remain hidden from any consuming code.</p>\n\n<p>A mature solution would probably involve the following design points:</p>\n\n<ul>\n<li>Public methods or properties are behavior (show, hide, position) or data-oriented (set data, get data, update data).</li>\n<li>All event handlers implemented by the Form are wrapped in appropriate thread delegation code to enforce Form thread-execution rules.</li>\n<li>Controls themselves would be data-bound to the underlying data structure (where appropriate) to reduce code.</li>\n</ul>\n\n<p>And that's not even mentioning meta-development things like unit tests.</p>\n"}]
['https://Stackoverflow.com/questions/5997', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/445/']