How do you identify classes?

When you are planning a program, what process do you follow to identify the classes that should be built?
closed account (jvqpDjzh)
When you program, you create a concrete representation of the ideas involved in the solution of a problem. The structure of a program should reflect this ideas in the most possible direct way:
a. If a concept can be thought as a separated idea, make it a class.
b. If a concept can be thought as a separated entity, make it an object.
c. If 2 classes have a common interface, make the interface a common abstract class.
d. If the implementation of 2 classes have something in common, make that something a base class.
e. If a class is an objects container, make it a template.
f. ...
g. If an amount of classes, templates, etc. are logically related to each other, put them in a namespace.
These are empiric and not immutable rules. Each suggestion should be applied when it seems correct to apply it. There's no other good substitute to the intelligence, to experience, to the common sense...

Author: B. Stroustrup
Translater: zwilu
Last edited on
Topic archived. No new replies allowed.