I have two unrelated types of data elements (objects) which I want to hold in two related types of containers, one for each element type. But this seems contradictory - for consistency, it seems that either
The problem with (a) is that I'd like to specify a base class interface for the containers which necessarily relates them through inheritance, and the problem with (b) is that the elements are have very different methods and members so defining a base class for those elements to shoehorn them into the container base class interface would be kind of a hack.
In other words, my elements do not follow the principle of substitutabilit y of objects that are related through inheritence, but their containers do, apart from a single method addelement() which adds the disparate elements to the containers.
What would be a good solution to this dilemma? Has anyone come across such a situation before?
(I originally posted this question as part of a larger question in this thread which which did not attract many responses, so I'm splitting up my question into different parts and skipping implementation details as suggested there.)
- the containers should be unrelated through inheritance, or
- the elements should be related through inheritance.
The problem with (a) is that I'd like to specify a base class interface for the containers which necessarily relates them through inheritance, and the problem with (b) is that the elements are have very different methods and members so defining a base class for those elements to shoehorn them into the container base class interface would be kind of a hack.
In other words, my elements do not follow the principle of substitutabilit y of objects that are related through inheritence, but their containers do, apart from a single method addelement() which adds the disparate elements to the containers.
What would be a good solution to this dilemma? Has anyone come across such a situation before?
(I originally posted this question as part of a larger question in this thread which which did not attract many responses, so I'm splitting up my question into different parts and skipping implementation details as suggested there.)
Comment