Archived

This topic is now archived and is closed to further replies.

pizza box

Using private specifier in classes

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites