5. 14 IDEAL CLASS DEFINITION

Now we have studied classes and objects in detail. Now we should try an entry level or level0 definition for ideal class.

Rule 1: The names selected for data members (variables) should be nouns. Names for methods should be verbs.

Rule 2: All the data members should be private. All methods should be public.

The logic behind these rules is straight forward. Data members represent attributes of real life objects. For example, marks, name, etc. Therefore, to represent these quantities we should be using nouns. The methods represent some specific action. Actions are best described by verbs.

If data members are public, the whole advantage of object orientation in terms of encapsulation and data hiding is lost. Hence, such ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.