A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very scrupulous about naming things in your program.
For example if my application was (as a typical business app) handling users, companies and addresses I'd have a User, a Company and an Address domain class - and probably somewhere a UserManager, a CompanyManager and an AddressManager would pop up that handles those things.
So can you tell what those UserManager, CompanyManager and AddressManager do? No, because Manager is a very very generic term that fits to anything you can do with your domain objects.
The article I read recommended using very specific names. If it was a C++ application and the UserManager's job was allocating and freeing users from the Heap it would not manage the users but to guard their birth and death. Hmm, maybe we could call this a UserSheperd.
Or maybe the UserManager's job is to examine each User object's data and sign the data cryptographically. Then we'd have a UserRecordsClerk.
Now that this idea stuck with me I try to apply it. And find this simple idea amazingly hard.
I can describe what the classes do and (as long as I don't slip into quick & dirty coding) the classes I write do exactly one thing. What I miss to go from that description to the names is a kind of catalogue of names, a vocabulary that maps the concepts to names.
Ultimately I'd like to have something like a pattern catalogue in my mind (frequently design patterns easily provide the object names, for example with a factory)
- Factory - Creates other objects (naming taken from the design pattern)
- Shepherd - A shepherd handles the lifetime of objects their creation and shutdown
- Synchronizer - Copies data between two or more objects (or object hierarchies)
Nanny - Helps objects reach "usable" state after creation - for example by wiring to other objects
etc etc.
So, how do you handle that issue? Do you have a fixed vocabulary, do you invent new names on the fly or do you consider naming things in the way as I describe as not-so-important or wrong?
P.S.: I'm also interested in links to articles and blogs discussing that issue. As a start here is the original article that got me thinking about it: Naming Java Classes without a 'Manager'
Update: Summary of answers
Here's a little summary of what I learned from this question in the meantime.
- Try not to create new methaphors (Nanny)
- Have a look at what other frameworks do
Further articles/books on this topic:
- What names do you find yourself prepending/appending to classes regularly?
- What’s the best approach to naming classes?
- Book: Design Patterns: Elements of Reusable Object-Oriented Software (Hardcover)
- Book: Patterns of Enterprise Application Architecture (Hardcover)
- Book: Implementation Patterns (Paperback)
And a current list of name prefixes/suffices I collected (subjectivly!) from the answers:
- Coordinator
- Builder
- Writer
- Reader
- Handler
- Container
- Protocol
- Target
- Converter
- Controller
- View
- Factory
- Entity
- Bucket
And a good tip on the road:
Don't get naming paralysis. Yes, names are very important but they're not important enough to waste huge amounts of time on. If you can't think up a good name in 10 minutes, move on.