In the project, our team uses lists of objects to perform bulk operations on data sets, which all must be processed in a similar way. In particular, different objects would ideally act in the same way, which would be very easily achieved with polymorphism. The problem I am facing is that inheritance implies that it is a relationship, not a relationship. For example, several objects have a damage counter, but to make it easy to use in the list of objects, you can use polymorphism, except that it is understood that this is a relation that will not be true. (A person is not a damage counter.)
The only solution I can think of is to have a member of the class returning the correct type of the object when it is implicitly cast instead of relying on inheritance. Would it be better to discard that a / has an ideal in exchange for ease of programming?
Edit: To be more specific, I use C ++, so using polymorphism will allow different objects to "act the same" in the sense that derived classes can be in the same list and controlled by a virtual function of the base class. Using an interface (or simulating them through inheritance) is similar to the solution I would like to use.
source
share