|
-
Jan 18th, 2003, 01:28 AM
#1
Thread Starter
Addicted Member
opinion on classes
if i have one variable in a class, and all i need of that variable is just to set it or get it, should i still make it private and then have accesor functions? I've heard this is proper decorum, but it seems like a lot of extra code for just a variable, when it would be just as easy to put it in the public section. if you would, post your thoughts
thanks
-
Jan 18th, 2003, 01:53 AM
#2
Frenzied Member
Re: opinion on classes
Originally posted by jmiller
if i have one variable in a class, and all i need of that variable is just to set it or get it, should i still make it private and then have accesor functions? I've heard this is proper decorum, but it seems like a lot of extra code for just a variable, when it would be just as easy to put it in the public section. if you would, post your thoughts
thanks
Accessors are the way to go, in my opinion. It may seem like a lot of work now, but it gets you in the habit of abstracting your objects.
Z.
-
Jan 18th, 2003, 10:09 AM
#3
Exactly. You might later want to give this variable bounds that should be checked in the accessors, or you might want to abstract the variable or make it part of a different class. If you don't use accessors now you'll then have to change every piece of code that uses the variable.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|