Response: Are Naming Conventions Still Needed For Abstract Classes?
I came across a post on the Adam Bien blog recently about using the prefix ‘Abstract‘ to define Abstract classes. The argument was that using the ‘Abstract‘ prefix is superfluous. I do not fully agree with the post. As I read the points he had mentioned on the post, here are some that came to mind
Abstract classes are already distinguishable by the keyword abstract. There is no need to further emphasize it.
A prefix “Abstract” doesn’t provide any additional value to the user – in contrary it blurs the actual intention
The Abstract in the class name helps a developer know that a class is Abstract even before they open it. Of course if some one bucks the convention and names a Concrete class abstract, it creates confusion but that scenario is rare.
Modern IDEs don’t let you instantiate an abstract class, even before saving / compiling.
The IDE would not let you instantiate the class whether or not the Abstract prefix is placed on the class name. If Abstract is used as a prefix, a developer would know before hand that the class is abstract.
If you really have to, it is easy to find / distinguish an abstract class with modern IDEs.
An IDE should be able to give you such a filter, but I wonder if it is a common feature across IDEs. I am not aware of a shortcut in eclipse that can do this (it might exist, I am just not aware of one). When I want to open an Abstract class, I type ctrl+shift+R and type ‘abstract’. That usually yields good results.
Even in UML class diagrams abstract classes are easy to distinguish – their name is italicized.
This is true. If you name your class AbstractSomething just because you want to distinguish them in UML diagrams, it is not justifiable.
So what good does an Abstract prefix do for a class ? Here is my opinion
- Developers know a class is Abstract without opening it.
- The name helps the developer realize that the class is meant to be inherited by a subclass, which will provide methods that the boiler plate does not.
- Provides a developer one more way to search for Abstract classes.
In summary I would say that whether or not you want to use the Abstract prefix depends. Most boiler plate classes that you encounter (non abstract) use the word Default as a prefix. Example – DefaultContentHandler. Boiler plate code with some abstract methods use the word ‘Abstract’ as a prefix. Example – AbstractList. There are classes that do not follow the convention, but I would still vote for the word Abstract as a prefix because of the advantages that it presents.