abstract class naming convention [closed]
Should we have a team coding standard that the names of abstract classes have prefix Abstract
? e.g.
public abstract class AbstractB implements B {}
Yes, in fact if you look at the javadocs of the standard library at http://download.oracle.com/javase/6/docs/api/ you'll find that the list of classes in the bottom-left frame begins with abstract classes using the naming convention you have mentioned in your question.
AbstractAction
AbstractAnnotationValueVisitor6
AbstractBorder
AbstractButton
AbstractCellEditor
AbstractCollection
AbstractColorChooserPanel
AbstractDocument
AbstractDocument.AttributeContext
AbstractDocument.Content
AbstractDocument.ElementEdit
AbstractElementVisitor6
AbstractExecutorService
AbstractInterruptibleChannel
AbstractLayoutCache
AbstractLayoutCache.NodeDimensions
AbstractList
AbstractListModel
AbstractMap
AbstractMap.SimpleEntry
AbstractMap.SimpleImmutableEntry
AbstractMarshallerImpl
AbstractMethodError
AbstractOwnableSynchronizer
AbstractPreferences
AbstractProcessor
AbstractQueue
AbstractQueuedLongSynchronizer
AbstractQueuedSynchronizer
AbstractScriptEngine
AbstractSelectableChannel
AbstractSelectionKey
AbstractSelector
AbstractSequentialList
AbstractSet
AbstractSpinnerModel
AbstractTableModel
AbstractTypeVisitor6
AbstractUndoableEdit
AbstractUnmarshallerImpl
AbstractWriter
Take any one of them, say the first one, and check its definition: AbstractAction
. It indeed implements Action
which is again similar to your convention. It's subclasses are named like: ClosedAction
, MaximizeAction
, etc.
Generally any kind of standard is a good thing in a team setting. Otherwise team members might name classes in such a way that only they understand and then you could get a mix of people's different coding styles which leads to confusion.
For Readability it does sound like a good idea. When reading code you will be able to know right away what the class is. As long as everyone follows the standard it is good.
I won't say yay or nay in an answer, but whatever you choose, use a good static analysis tool to ensure it.
Modern IDEs will pop up descriptive text when you hover over an object. Prefixing is redundant in this case.
As with most questions of this type: "it depends". I like consistency and clarity, so if it works for you and your shop, great. However, if you have legacy Abstract classes, you would then want to go back and refactor them to the same naming convention.
精彩评论