Avoid verb classes
From CSSEMediaWiki
(Difference between revisions)
m |
m (Reverted edits by Ebybymic (Talk); changed back to last version by Stephen Fitchett) |
(One intermediate revision by one user not shown) |
Latest revision as of 03:11, 25 November 2010
- Do not turn an operation into a class. Be suspicious of any class whose name is a verb or derived from a verb. Especially those which have only one piece of meaningful behavior (i.e. do not count sets, gets, and prints). Ask if that piece of meaningful behavior needs to be migrated to some existing or undiscovered class. --Riel's Heuristic 3.9, Arthur Riel 1996
Class names should always consist of nouns, mostly in singular since one instance of that class will be created at a time. Classes represent real or abstract objects (like cars or computing structures) and therefore shouldn't have a verb name.
If a class name is a verb, this is a strong indicator that the functionality of that class can be put into an existing class. For example, the Interface Move in the Frogs design contains only three abstract method definitions. The ability to move by swimming or hopping belongs to the frog, though. If a superclass of frog is desired, the class should have the name Movable or Movable Object.