1

I've read somewhere that it's a bad idea to name classes after verbs (manager/browser/editor)

but what's the proper name for manager/browser/editor?

EDIT:

the problem is that system could turn in a big ball of "services" - tiny objects which does something specific and does not contain any data - which is bad (at least because it just queries other objects)

but I also need to be able add new "managers" easily (right now app needs to manage users, ftp accounts, mail accounts, etc.)

0

2 Answers 2

4

The main reason why names ending in Manager or Browser or Editor are sometimes bad is that they're vague and unspecific, and don't say enough about what the FooManager class is actually doing with Foos.

For exactly that reason, there is no general answer to the question "what should they be replaced with?".

A class name should (so far as is possible given its brevity) say what an instance of the class does. If you really can't say anything more about what a FooManager does than that it manages Foos, then call the class FooManager (and consider whether perhaps its respponsibilities should be divided among multiple other classes with better-focused responsibilities). If you can say something more specific, and you can do so briefly, then that should indicate what name would be better.

(Of course if your class is called WebBrowser or TextEditor or SeniorManager then none of the above applies; that isn't the sort of thing the folklore about not giving classes that sort of name is aimed at. :-) )

6
  • so UserManager, MailAccountsManager, etc. are all ok? I was also thinking to factor some functionality together in their modules (UserModule - users, payments, MailModule - mail accs, mail aliases) and use dynamic adapters to attach them in the rest of system. - like AppSection(callback) where callback would point directly to some method on module Commented Mar 21, 2011 at 1:34
  • It might be better to find something more informative than, say, UserManager (which is pretty vague about exactly what instances of the class are doing). See stackoverflow.com/questions/1866794/… for an earlier discussion of this. Commented Mar 21, 2011 at 1:37
  • interesting discussion - thx for the link. Is then MailModule better idea (including CRUD for all mail entities?) - still it smells like duplication (add_mailaccount, add_mailalias, add_xxx) Commented Mar 21, 2011 at 1:51
  • MailModule doesn't feel great to me either, but of course I haven't seen the rest of your system! Commented Mar 21, 2011 at 1:55
  • A-ha :-) closer the program models the real world problem, the better the program will be. - so the right object should be application, right? because it does all of the work Commented Mar 21, 2011 at 2:07
6

"Manager", "Browser", and "Editor" are nouns, not verbs. "Manage", "Browse", and "Edit" are verbs, and not particularly good class names!

1
  • read edit why it's bad Commented Mar 21, 2011 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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