Disclaimer: the following is written without further distinction in the object oriented terminology as C# is implementing it: classes, interfaces and instances, etc.
Let's assume the following scenario: there are different classes
Egg with no shared inheritance hierarchy except for
Object at the top. All those classes implement the interface
IPeelable which obviously makes sense for all three. Each of the
IPeelable implementations of course is using methods specific to their respective class.
MushyPulp wants to build on top of
IPeelable classes but needs to bring its own member variables like
MushyPulp can e.g. increase in volume if you first
peel a little more and then
squeeze a little more, where
squeeze is introduced only in
MushyPulp and independent of the exact substance that is squeezed.
MushyPulp instance in my eyes in essence is a
IPeelable object. My problem: I somehow don't understand how to define this relationship in C#. The only way I could make it work is to have a private
IPeelable instance in
MushyPulp and reroute all
IPeelable methods of
MushyPulp through to this object - the code of course is a entirely boiler-plate indirection.
From a technical perspective it looks like what I want would be multiple inheritance in disguise - is there a way to have that, restricted to interfaces (somehow) in C#?
EDIT: My creative translation of my actual programming problem towards a food based example didn't work out so well. I rephrase my question a bit towards more technical terms:
I have a range of otherwise completely unrelated producer classes which can put out
bytes sequentially (they implement the interface
IPeelable). And I want to have a more complex "something" that can put out
bytes sequentially but also emit whole datagrams, costructed from a sequence of those
bytes, depending on the type of data I am asking from it. So either a spoon- cup- or plateful of mushy pulp (
bytes interpreted and transformed, e.g. type cast to a
float) or a
byte of peeled substance. The source of the substance is understandably anonymous beyond the
IPeelable interface. The question is, what is the "something"? A class with a member of an
IPeelable capable class as for now, but is that the final word on OO here?