Reputation:
Good morning,
I will be having many subclasses, subclasses of subclasses, and so on. How to name them properly in order to avoid a mess in naming and make them consistent?
I mean, I could do this:
i.e. now subclasses are readable, but there is no consistency, so when you see an unknown class for you, you must read all its name to understand its purpose.
I also can name them this way:
It better, but now its harder to read. There may be classes like "LargeAnimalRed" instead of "RedLargeAnimal" that is much more readable.
So I see the third option:
Now they have Name + Group + Modification, i.e. you see all options and do not need to determine what is what, but I did not see such naming convention.
What do you think about this question and examples?
Is the third variant is acceptable in the community?
Upvotes: 3
Views: 603
Reputation: 184
What do you think about this question and examples?
The fact that you took time to ask this is good, and the examples you provided are well understood.
Is the third variant is acceptable in the community?
No. Each language has its own coding and naming standards. In this case, I don't know of any language that has This_Convention. If it's java you're speaking of, then the usual PascalCase should do.
As per your question, I would say that if a class can't be easily named, it might hint at some bad design decisions that were made.
Do LargeAnimal and SmallAnimal really have different properties that make them logically separable? Do all large animals share the same methods/fields that all small animals don't have?
Classes and objects (usually) represent real life concepts and objects. If you have an instance foo of some class Bar, you should be able to comfortably say "foo is a (type of) Bar".
Can you say "foo is a LargeAnimalMeat"?
To conclude, I think you should reconsider these names, and if you aren't familiar with the concept of Composition, I would suggest you read about it, because in many cases it is a more appropriate solution, rather than inheritance.
https://en.wikipedia.org/wiki/Composition_over_inheritance
Upvotes: 1