Helper Functions

The interface of a class consists of its public members. Usually, private members represent implementation details and are not exposed to other classes and users. Private members can be member functions, not just data members. When is it useful to declare member functions private? Suppose you have a multimedia player class whose public member functions, e.g., play(), zoom() and stop(), call internal member functions, or helper functions, that take care of internal operations such as managing memory buffers, threads and files. These internal operations are not supposed to be used by any other classes or users because they are highly specialized and deal with low-level facilities such as physical devices and memory pages. As you can see these helper functions can vary with each new release or port to another platform. Therefore, they are declared private. Another example, Shape::Draw() can call low-level, platform-dependent functions that initialize screen drivers and define a client area. Declare such internal members private if they are meant to be used only in class Shape.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: