Avoid verb classes
From CSSEMediaWiki
(Difference between revisions)
(Added See also section) |
m |
||
Line 1: | Line 1: | ||
+ | :''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. | 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. | ||
Line 5: | Line 6: | ||
== See also == | == See also == | ||
[[Eliminate irrelevant classes]] | [[Eliminate irrelevant classes]] | ||
+ | |||
+ | [[Category:Riel's heuristics]] |
Revision as of 04:21, 22 July 2009
- 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.