Public and private data in C++ Programming:-
A C++ header file defining a class is split into two parts. These two parts specify the public and private parts of the class. The distinction between these two is straightforward. Anything defined in the public part of the file is available to any program that might make use of the class, while anything defined in the private part is available only to the class itself.
This is a very powerful mechanism. It means that, as long as the public part of the class (the interface) remains constant, the private part can be changed if needed. This means that a programmer using the class need only know about the class’s public face; the private face remains hidden and can be changed.
At the same time, the programmer working on the class can change the details of the private part, perhaps to implement something more efficiently, without risking any unpleasant effects on programs that use the class.
An analogy would be the controls of a car. The normal controls – the steering wheel, pedals, handbrake and so on – remain constant and form the public interface to the car’s engine. Any changes that a mechanic might make to the engine itself are totally independent of this interface; anything that changes in the engine is private and is something that the driver doesn’t
need to know anything about. The public interface of the car always works in the same way, and this cannot be altered by any changes made to the engine.


LinkBack URL
About LinkBacks
Reply With Quote

LinkBacks Enabled by vBSEO
Bookmarks