What is a better name than Manager, Processor etc?

2020-02-17 09:47发布

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.

8条回答
啃猪蹄的小仙女
2楼-- · 2020-02-17 10:05

In the example of your ConnectionManager class, it is possible that the class is more indicative of a design flaw which necessitates a "bad" name. Is the class doing something besides performing actions that could just as easily be done in a singleton subclass called MyDatabaseConnection?

查看更多
够拽才男人
3楼-- · 2020-02-17 10:07

Take for instance name DataProcessor.

First it is true that each function works with data, takes data or return some data unless is

void f(void)

But if it is such type of function it absolutely makes something so it is Processor in any case.

DataProcessor is basically anything because it does no say what it manipulates and how. So you should replace

DataProcessor with UserInfoStore for instance.

查看更多
够拽才男人
4楼-- · 2020-02-17 10:10

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!

查看更多
beautiful°
5楼-- · 2020-02-17 10:12

"Helper", "Common", "Core", "Utilities" seems equal or worst than "Manager". Them don't say nothing about what they do.
"Factory" is absolutely wrong here.
Alternative names are "Coordinator" or "Controller".

yous said: I have a class that is responsible for starting and stopping connections. So I named it ConnectionManager.

If the class just "start" and "stop" the connection, why not "ConnectionSwitcher" ?


you said: I have used these everywhere.

I have many *Manager classes too. Today I decided to change the name of "AccountManager". It uses the Account repository to perform CRUD operations.

I splitted it in "AccountSecurity" and "AccountOperations".

Them exists in MyProject.BusinessLogic namespace and both uses AccountRepository class that expose the CRUD methods. The former is responsible for actions like "Login" and "ChangePassword". The latter is responsible for CRUD operations against the database but regulated by some logic, for example if exists some registry records for the Account it cannot be deleted. (The "AccountOperations" uses also other repositories to retrieve needed informations)

I'm not happy with "operations" and I'm searching something better (Coordinator, Supervisor...) but it is a start.

My case would be an example of the way to think at it.

查看更多
走好不送
6楼-- · 2020-02-17 10:13

I tend to use the word "Initialize" or "Initializer" quite frequently. If it's anything else, I usually think of a synonym that is really long compared to the first thing I thought of. I also use the term "Parser" and other things.

查看更多
一夜七次
7楼-- · 2020-02-17 10:13

dont be too concerned about the name, dont pay much attention to it unless you or someone really dont like it.

查看更多
登录 后发表回答