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
(a) the containers should be unrelated through inheritance, or
(b) 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 substitutability of objects that are related through inheritance, 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?