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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access