I'm wondering what is better in terms of good OOP desing, clean code, flexibility and avoiding code smells in the future. Image situation, where you have a lot of very similar objects you need to represent as classes. These classes are without any specific functionality, just data classes and are different just by name (and context) Example:
Class A
{
String name;
string description;
}
Class B
{
String name;
String count;
String description;
}
Class C
{
String name;
String count;
String description;
String imageUrl;
}
Class D
{
String name;
String count;
}
Class E
{
String name;
String count;
String imageUrl;
String age;
}
Would it be better to keep them in separate classes, to get "better" readability, but wit many code repetitions, or would it be better to use inheritance to be more DRY?
By using inheritance, you will end up with something like this, but class names will lost it contextual meaning (because of the is-a, not has-a):
Class A
{
String name;
String description;
}
Class B : A
{
String count;
}
Class C : B
{
String imageUrl;
}
Class D : C
{
String age;
}
I know inheritance is not and should not be used for code reuse, but I don't see any other possible way how to reduce code repetition in such case.