Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What's the coding convention about public/private members in WPF with binding?

I know this is a largely debated question in stackoverflow (as e.g. in Should I use public or private variables?), but I haven’d been able to find a suitable answer to my doubt.

Shortly said, OO coding etiquette mandates that members of a class be kept private or that getters/setters be used as an alternative.

However, data binding in WPF will not succeed unless the bound class members are public. So, what’s the best way out here? Shall I accept declaring public members as an ugly but necessary compromise?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Data binding is normally used on properties, not fields, so that does not contradict the general principle that fields should be kept private.

The sentence "that members of a class be kept private" is, as such, not correct. Fields should be kept private. The term "members" means fields as well as methods or properties. And of course, it is perfectly sensible to have methods or properties that are public.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading