Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Using private specifier in classes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 pizza box   Members   -  Reputation: 168

Like
Likes
Like

Posted 16 February 2002 - 04:41 PM

I am creating a lot of classes for the games I make, and in all the reference books I read, variables should be defined as private. But these books were all for systems programming, and none considered speed an issue. So whenever I need to get a variable, I have to call a function to retrieve it or alter it. Is this a preferable method when using Object-Oriented programming, or should I make all my variables public for speed reasons?

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 16 February 2002 - 05:56 PM

One of the main objectives of OOP programming techniques is to protect the data''s integrity. By making your variables private and accessing them via accessor functions you can prevent miss-uses of the data. Yes there is a speed loss, but with todays processors it''s not very noticable.

#3 kvh   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 February 2002 - 02:49 AM

Accessor functions are usually very simple and short. If you inline them, the compiler will almost always be able to optimize the overhead away.

EDIT: assuming you use C++ ...

Edited by - kvh on February 17, 2002 9:54:45 AM

#4 pizza box   Members   -  Reputation: 168

Like
Likes
Like

Posted 17 February 2002 - 03:46 AM

Ok, thanks for your help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS