Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a better name than Manager, Processor etc? [closed]

Tags:

I am reading the book Clean Code http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

The author mentions that you should avoid words like Manager, Processor, Data or Info in the name of the class. I have used these everywhere. What are some better names? I have a class that is responsible for starting and stopping connections. So I named it ConnectionManager.

like image 676
uriDium Avatar asked Apr 06 '11 16:04

uriDium


2 Answers

Wait!

The point of the book is, that Manager in the classname means the class does more than one thing. Robert C. Martin refers in this section to the Single Responsibility Principle!

This is not about the name, its about the classes which are usually named like this. Changing the name won't reduce the responsibilities of a class!

like image 71
myAces Avatar answered Nov 02 '22 18:11

myAces


My guess is the book makes this point because it's trying to encourage you to choose a more descriptive name for your class. There's no "naming convention" to follow here; that's the problem you fell into in the first place. Any universal naming convention won't be able to consider the specific class and choose the best name for it. Expressivity is more important than following a naming convention. Calling a class a "Manager" or a "Processor" doesn't say very much about it and what it does to a person who is reading your code for the first time.

If you really can't think of anything better, there's nothing inherently wrong with naming a class ConnectionManager. But I'd at least name it after the type of collections that it manages. Or maybe how it manages those collections. Or why it manages those collections.

Also consider that following "one-size-fits-all" rules rarely helped anyone to write better code (at least, not better in the sense of "more understandable" or "more expressive). I tend to postfix the names of all my native wrapper classes with Manager. For example, I might have classes called DwmManager, or VisualStylesManager. In that very specific case, it does mean something to me. If I see a class named Manager in my code base, I know it wraps a bunch of closely-related functionality. You have to make the decision on a case-by-case basis, understanding what you're ultimately trying to accomplish.

If you read Code Complete and missed the part about writing code that's clear and understandable (and therefore maintainable), you might have missed the point.

like image 42
Cody Gray Avatar answered Nov 02 '22 19:11

Cody Gray