If you only reference member variables inside the object they are contained in, do you need to create properties for those member variables, or can you just reference them directly?
If they are private and not visible outside the class, then it is more a question of taste and style than anything else.
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]
But if I make a property, then it will be visible outside the class correct? If it doesn't need to be accessible outside the class then I can just refer to it by it's name inside the local object instead of creating a property?
the language may have some bearing here. properties are most common in .net. assuming that is the language you are talking about a property is really just syntax sugar for get/set functions.
Code:
string Foo {get;set;}
gets compiled to
Code:
string _getFoo;
void _setFoo(string value);
if you think of properties as functions without () then you can decide if it makes sense to use protected/private properties.
if you need to encapsulate logic, even within a class itself, then a property makes sense. other wise a field works just as well.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.