A
A
andreycha2011-08-29 12:54:33
Programming
andreycha, 2011-08-29 12:54:33

Clean code: class names?

From "Clean Code":

Class and object names must be nouns and their combinations: Customer, WikiPage, Account, and AddressParser. Avoid using words such as Manager, Processor, Data, or Info in class names.

I wonder why Martin and the company are not satisfied with Manager and Processor, but are satisfied with Parser? Too "general" names that do not say anything about what exactly the class does?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
S
sainnr, 2011-08-29
@sainnr

I think that it is the Parser that also does not suit them, just like the Manager or Processor. As a valid name, they cite AddressParser as an example, i.e. parser applicable specifically to the address. Likewise, options such as AccountManager or TemplateProcessor would be valid.

O
Ogra, 2011-08-29
@Ogra

By the word Parser, I already understand what the class does - it takes something big (most likely, text) and parses it into small components. I roughly understand the purpose of the class and its interface.
But Manager / Processor / Data / Info ... Too general words. Exaggerating - here is the DataProcessor class - what does it do? Processes data, prompts KO! But what data? How does it process?
Another example: AddressProcessor . What does this class do? It can convert all addresses to the same format, it can create a graph for a logistics program, or it can process DNS records.
You can always find a more accurate replacement for the words Manage / Process / Data / Info

I
ixSci, 2011-08-29
@ixSci

The simplest thing is to email them and ask them directly. I think they will be better able to explain their point of view than we are composing here now.

R
Rafael Osipov, 2011-08-29
@Rafael

According to the same book, the class name should define its scope of responsibility. Manager and Processor define too broad a field of responsibility. Parser - a specific description of responsibility (parsing something).

I
Ilya Plotnikov, 2011-08-29
@ilyaplot

Apparently in its structure Manager, Processor, Data and Info are system classes and do not represent a data object. Apparently he wanted to say that you need to clearly separate data and data processing classes.

K
korvindest, 2011-08-29
@korvindest

Manager, Processor, Data or Info are really too general words. Manager, you can call almost any class that stores any data or access to resources. Similarly, with all the other words from this list. And Info is generally a masterpiece that I have repeatedly met in code.
For example, instead of calling the class NetworkConectionManager, you can call it NetworkConections and this, in my opinion, will be clearer.

A
andreycha, 2011-09-02
@andreycha

The answer was found hundreds of pages later:

The class name should describe its responsibilities. [...] If you can't find a clear, short name for a class, it's probably too big. The more obscure the class name, the more likely it is to have too many responsibilities. In particular, the presence of the rogue words "Processor", "Manager", and "Super" in class names is often indicative of an undesirable pooling of responsibilities.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question