抽象类命名约定

时间:2011-07-28 15:37:09

标签: java coding-style

我们是否应该有团队编码标准,抽象类的名称前缀为Abstract? e.g。

public abstract class AbstractB implements B {}

6 个答案:

答案 0 :(得分:80)

是的,实际上如果你在http://download.oracle.com/javase/6/docs/api/查看标准库的javadocs,你会发现左下角框架中的类列表以抽象类开头,使用你在上面提到的命名约定。你的问题。

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

选择其中任何一个,说出第一个,并检查其定义:AbstractAction。它确实实现了Action,它再次类似于你的约定。它的子类命名为:ClosedActionMaximizeAction等。

答案 1 :(得分:12)

一般来说,任何一种标准在团队环境中都是一件好事。 否则,团队成员可能会以这样一种方式命名类,只有他们理解,然后你才能混合使用不同的编码风格,这会导致混乱。

答案 2 :(得分:5)

对于可读性,它听起来像个好主意。阅读代码时,您将能够立即知道课程的内容。只要每个人都遵循标准就行了。

答案 3 :(得分:3)

当您将鼠标悬停在某个对象上时,现代IDE会弹出描述性文字。在这种情况下,前缀是多余的。

答案 4 :(得分:3)

我不会在答案中说yay或nay,但无论你选择什么,都要使用好的static analysis tool来确保答案。

答案 5 :(得分:2)

与此类型的大多数问题一样:“它取决于”。我喜欢一致性和清晰度,所以如果它适合你和你的商店,那就太好了。但是,如果您有遗留的抽象类,那么您可能希望返回并将它们重构为相同的命名约定。