Question

I am working on a project with class hierarchy as in the image. It has many classes but i am showing some of them. The problem is that there are some attributes that repeat in many classes but not in all classes. I want to reduce the occurance by creating a new class with common attributes, and use the class as Instance variable in all the classes. This way i can maintain my class instead of maintaining all the occurances all over the code. These attributes has no operation, and class also have methods so it does to fulfill the definition of class. The class has many levels of inheritance and if create subclasses, it has yo-yo problem then, so i do not want them to be further subclassed. I want to know is there any other way? or any better way to do it.

Class diagram

Was it helpful?

Solution

You have yo-yo problem when you have all concrete classes. I would suggest to make an abstract class and put all common attributes there. I also see that you have Unit value attributes repeating for same attribute. For this, you can use hash map to have only one attribute with two values for unit and for value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top