Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am reading Clean Code by Uncle Bob. Because I am not a native-English speaker, I couldn't understand following statement:

Classes and objects should have noun or noun phrase names like Customer, WikiPage, Account, and AddressParser. Avoid words like Manager, Processor, Data, or Info in the name of a class. A class name should not be a verb.

As I know, none of the Manager, Processor, Data, and Info is a verb, isn't it? What is the actual point he want to emphasize?

share|improve this question
    
maybe Uncle Bob is adopting RESTful thinking in extolling the virtues of resource-as-objects. –  rwong May 9 '13 at 19:35
add comment

2 Answers

up vote 17 down vote accepted

The three points are separate:

  • Class names should be nouns or noun phrases. This means that the name of the class should be something that would be the subject of a verb. In the case of object-oriented design, methods would be the verbs that take place on the thing that the class is a representation of.

  • Some words should be avoided. Manager indicates a possible god class. Info and Data may indicate a dummy data container. Words like this may indicate poor modeling of the problem space.

  • Verbs should never be class names. See the first point - classes model things, methods model actions.

share|improve this answer
    
Words like this may indicate poor modeling of the problem space. - Well, one would think, either the problem space is modelled poorly or not, independent of the names choosen. A good name doesn't help a poor design; and a good design is only marginally hurt by a poor name. –  Ingo May 9 '13 at 22:15
    
And you could take this a step lower when considering how you actually build your class and how it interacts with the outside world - the class's properties would generally be nouns, while the class's methods would generally be verbs –  PeteH May 10 '13 at 19:59
add comment

He's trying to draw a distinction between things (nouns) and actions (verbs). In conventional objected-oriented design, we think of classes as things, and their methods as the actions those things can perform. To manage is to take care of or coordinate, while manager is a person or thing that manages.

Introductory books usually boil this down to the simplest and most obvious terms possible like a class named Dog, with methods Bark and Bite. In real world classes, the distinction is often a little more subtle, but it's still there. I believe the point Uncle Bob is making, however, is that while manager is a noun, but it puts a lot of attention on the what the manager does, and not what it is-it's too vague of a word for describing exactly what is being managed or how.

share|improve this answer
    
Unfortunately, this kind of thinking can lead to wrong designs. One of the prime examples is the classic introductory example of a bank account. In almost all OO textbooks, Account is an object, balance is a field and transfer is method. But the correct design would be: Transfer is an object, account is a field and balance is a method. That's how banking systems are actually implemented and how banking actually worked before computers. –  Jörg W Mittag May 10 '13 at 1:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.