Results 1 to 3 of 3

Thread: opinion on classes

  1. #1

    Thread Starter
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238

    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

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710

    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.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width