Using “Base” in a Class Name

前端 未结 13 2023
旧巷少年郎
旧巷少年郎 2020-12-30 21:07

Is it acceptable to use the word \'Base\' in a class name which is a the bottom of the inheritance tree?

I have always found this a bit of a cop-out, just wondering

相关标签:
13条回答
  • 2020-12-30 21:28

    I usually go with IFoo for the interface and AbstractFoo for the skeletal implementation, which is a mix of .NET and Java conventions.

    0 讨论(0)
  • 2020-12-30 21:29

    It seems like any principled answer will end up being no... However, comma, when I'm looking at code I'm not particularly familiar with, which happens a lot in python (where the source code is sometimes the only dependable documentation), I find it really helpful when a class has Base in it. Python is different from other OO languages where the class is defined with an "abstract" or "interface" specifier though. For naming, I like to ask myself "if I have never seen this code before, which way would make it easier for me to understand this code?" (Then, depending on how lazy I'm feeling, I name it accordingly).

    0 讨论(0)
  • 2020-12-30 21:31

    In Java I tend to provide a base implementation of an interface Foo in an abstract class FooBase. I think that is perfectly ok, and makes the connection to the interface very clear and regular.

    Without the interface I would call the abstract base class Foo.

    0 讨论(0)
  • 2020-12-30 21:32

    "Abstract" prefix maybe?

    0 讨论(0)
  • 2020-12-30 21:33

    I think it should probably be avoided where possible in favour of an identifier that actually describes what it is!

    This question is difficult to answer because it's abstract. I might, for example, consider calling the base of MyClassA and MyClassB, "MyClass".

    0 讨论(0)
  • 2020-12-30 21:35

    "All your BaseClass are belong to us."

    I side with a definitive no, with a single exception. If you are writing an app to manage military installations or baseball stadiums, go for it.

    0 讨论(0)
提交回复
热议问题