I was thinking about this subject because there are some complaints in the software world about how inheritance creates a hard coupling that makes code hard to update or refactor.
Because of that many people prefer composition over inheritance. This idea is just a scratch since I didn't think deeply about this yet.
So the idea is something like that(I will use standard C++ syntax here):
class Base
{
// lots of things here;
};
class Derived : in_place public Base
{
// in_place would essentially create a nested Base class here, a Base object too, which will make it more a
// composition structure than a typically inheritance, but let users to use all easy syntax from inheritance.
// Also, changes in the original Base class would not(or would, depending on use choice)
// affect the nested Base class inside Derived.
};
// A polymorphic function:
int fun(pmorph Base *ptr)
{
// "pmorph" would be a special polymorphic pointer that could contain multiple addresses type fields,
// like one for Base class type and another to derived class types to make polymorphism work.
// May be something faster than a vtable.
}
I was thinking about this subject because there are some complaints in the software world about how inheritance creates a hard coupling that makes code hard to update or refactor.
Because of that many people prefer composition over inheritance. This idea is just a scratch since I didn't think deeply about this yet.
So the idea is something like that(I will use standard C++ syntax here):