Class Names and Method Names

7 07 2011

The naming of “things” in software is important. It’s important because it is everywhere. Variables, functions, arguments, classes, source files and directories all require names and tell a story of how the code works. In order to be useful names must be meaningful. When I say meaningful I mean a name should reveal the intent of that entity, its reason for existence. Creating meaningful names is harder than it sounds but in class and method naming there are some simple rules of thumb you can follow.

Classes and objects should have noun or noun phrase names like Customer, Book, AddressParser and CustomerComparer. Avoid words like Manager, Processor, Data, or Info in the name of a class, they don’t mean anything. A class name should not be a verb. Methods should have verb or verb phrase names like Save, Listen, or CompareDetails.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: