Remix.run Logo
Mikhail_Edoshin 6 hours ago

Hierarchy (and thus "inheritance") is a way to express that several different things share the same quality. They are different in general, but same in some way. It is a very natural way for people to express such a thing and no wonder it is so widespread. But it is not the only way nor the general way, of course.

Composition is not an opposite to inheritance. An opposite would be something like:

    Message A ( ... ):
        Type B: { ... }
        Type C: { ... }
 
Or, if the body of the method is same ("a parent method"):

    Type B, Type C:
        Message A ( ... ): { ... }
Here we do not give A and B places in the hierarchy but merely say they respond to the same message or that even the procedure is same.

I do not know if any meaningful and systematic alternative to a hierarchical way exists in any programming notations. Interface spec is a partial way, but that's all. (I know only a few notations, of course).