Re: Property or get/set methods ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: David Browne (meat_at_hotmail.com)
Date: 12/14/04


Date: Tue, 14 Dec 2004 16:38:50 -0600


"Mike Newton" <MNewton@discussions.microsoft.com> wrote in message
news:%23gkdA0h4EHA.2192@TK2MSFTNGP14.phx.gbl...
>I don't expose public class variables at all. It's a bad idea, and breaks
>encapsulation. It's easy to take a ref from a public class variable and
>turn it into something that it shouldn't be. Properties make sure that
>your vars are yours.
>
> Personally, I believe that exposing public variables is just a sign of
> laziness.

Yes. I am lazy. And I agree that exposing public variables is just a sign
of laziness.

But laziness in programming is a vice in inverse proportion to the type
safety of the language.

For POD types, private types, and "friend" types, the cost of variable
encapsulation is not always worth the effort.

David