Suppose I have an abstract class named Task.
Is there a standard or convention that would suggest I should name it AbstractTask instead?
|
Suppose I have an abstract class named Is there a standard or convention that would suggest I should name it |
|||
|
|
According to Bloch's Effective Java (Item 18) the Abstract prefix is a convention used in a special case.
But Bloch also points out that the name SkeletalInterface would have made sense, but concludes that
As other answers have pointed out, in general there is no reason to apply this naming convention to all abstract classes. |
|||||
|
|
There is no convention. It's all about what will help you, as the developer, code faster and better, and help others understand your code. Ask the people who will be seeing and maintaining the code. What would they rather see? What will make it easier on them? Then name it based on what they'd like. On another note, Code Conventions for the Java Programming Language: 9. Naming Conventions suggests no requirement:
|
||||
|
No. Intellisense will trivially tell me if it is abstract, so you're just violating DRY here. |
|||||||||||||||||||||
|
|
This is somewhat a matter of preference (but borderline bad practice), but most people don't like seeing part of the qualifiers in the name of the class. Most IDE's will make that information easily available to you anyway, so putting it in the name isn't necessary, and it will be cleaner to just omit it. It's reminiscent of hungarian notation for variable naming, and that's certainly considered bad form now-a-days. I recommend simply calling it |
||||
|
|
|
In .NET, the use of "Base" as a suffix to denote an abstract base class is often seen. I would defer to the other answers as to whether this is common practice in Java. |
|||||||||||||||||||
|
|
A good rule of thumb is to not include properties in a name that are obvious from the syntax. Since in Java, you need to mark an abstract class with the aptly named The usual exception to the rule is when the name is ambiguous. If, for whatever reason, there is a concrete subclass |
|||
|
|
This tells me this is an Abstract class. Adding a prefix is a tautology and anti-pattern and not appropriate in most cases, see the link where it talks about In most cases In most cases if you can't come up with a more descriptive name you probably need to do some redesign. |
||||
|
|
|
In my opinion, an entity's name shouldn't convey information about its type structure, but about its semantics. So it doesn't make sense to define your class as "AbstractSomething" if the abstraction is not part of its runtime goal. That it is a base abstract class is visible for the programmer, and doesn't need to be reflected in the name. However, if makes perfect to call an implementation of an abstract factory an AbstractFactory, because that does relate to the class's intent. In general, favor naming convention that help to convey the most information about the goal of your class. Similarly, stay clear from Consider:
As opposed to:
I prefer the latter by far. This, in some respect, similar to the blatant misuse of the Hungarian Notation that latter gave it its bad rep, as people wrongly started to interpret it as requiring developers to prefix their variables with an indicator of the variable's type. While this can sometimes have its uses (mostly if you are lazy to look up the type's definition), it's mostly useless. Simonyi's original idea with the Hungarian Notation was to use it as a mnemonic to remind the developer of the entity's capabilities, not of its type. |
||||
|
|
|
I'm not a Java developer (INAJD?) and don't know the standard nomenclature for such things, but I think |
|||||||
|
|
|
What if you want to write an abstract It's not conventional and it can easily confuse people. |
|||
|
|
|
My five cents, Probably you'll have implementations of that abstract class and they will be named 'SomeSpecificTask', 'TaskWithBubbles', 'StrangeTask' etc. So there won't be a name clash between your abstract 'Task' and them. Additionally, 'abstract' word is about language syntax, not business domain entities, so I'd prefer not to use it as a part of the name. On the other hand, in one answer here I saw excerpt from J.Bloch Effective Java which says that using 'abstract' as a part of a name is a well-established practice. It may be so. But anyway in official java code conventions there is nothing about that. |
|||
|
|
|
If you work in a team, then entire team must decide whether you should prefix abstract classes with "Abstract". If you work on your own, then it's entirely up to you, not me or anybody else on this site. |
|||
|
|
|
I have done this. I did add 'Abstract' as prefix to my abstract class named AbstractOperation. The reason I did this was there was another package that had a non abstract class named Operation, and It helped my team and the programmers who took over later in avoiding any confusion between the two. |
|||
|
|