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.)
2 Answers 2
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 Foo
s.
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 Foo
s, 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. :-) )
-
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 moduleKamil Tomšík– Kamil Tomšík2011年03月21日 01:34:50 +00:00Commented 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.Gareth McCaughan– Gareth McCaughan2011年03月21日 01:37:59 +00:00Commented 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)Kamil Tomšík– Kamil Tomšík2011年03月21日 01:51:17 +00:00Commented 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!Gareth McCaughan– Gareth McCaughan2011年03月21日 01:55:34 +00:00Commented 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 workKamil Tomšík– Kamil Tomšík2011年03月21日 02:07:44 +00:00Commented Mar 21, 2011 at 2:07
"Manager", "Browser", and "Editor" are nouns, not verbs. "Manage", "Browse", and "Edit" are verbs, and not particularly good class names!
-
read edit why it's badKamil Tomšík– Kamil Tomšík2011年03月21日 01:36:23 +00:00Commented Mar 21, 2011 at 1:36