2014-12-27

multi-inheritance

5.10: adda/oop/multi-inheritance:
12.26..27: summary:
. I played around with the idea of mult-inheritance
in 2010/062010/11,  and 2012;
after this latest exploration in 2014/05,
I'm wondering if mult-inheritance is worth it;
because it could easily become confusing
knowing how many roles are affected by assignments .
5.10:
. the idea of multi-inheritance
is to have an object with multiple roles
with a separate self for each role;
eg, if something inherits both string and number
it actually has separate components for
the state of a string and a number .

. what if the roles share operation names?
eg, in (n + multi) what n and multi have in common
is a numeric role, so (+) is a numeric operation,
and multi is expected to return a number;
thus, our system's type mgr's have to deal with
not only subtypes but also with roles:
number mgt is asking not only
are you a float or integer or fraction,
but also, if you are mult-roled,
give me the address of your number-typed self .

. for the multi-role obj in our example,
there are possibly 2 assignment operations:
(number)`= (number) and
(string)`= (string).
[12.24:
. if just the source is multi-role,
then the destination type chooses one assignment;
else if just the destination is multi-role,
then the source chooses one assignment;
else if both the source and destination are multi-role
then assignment happens to all matching roles;
eg, given {string, num}`= {bool, num},
only the num would be assigned .
]
. if the number and string types
share names of self-modifying operations,
then how does our mult-role obj ask
"which self did you order this for?"
. when we make a call to a function,
we are the client,
and the function's owner is the server;
the client supplies the server with parameters
that are needed in servicing the call .
. usually when servers ask for a parameter input,
they are not the ones expecting a multi-role player;
eg, they will declare their parameter a string,
and the client will dictate that the
parameter's input is to be a multi-role,
so when the server, as part of the call,
in turn calls something like param`zero-me,
the compiler will send to the param
the message ( number.type`zero-me );
[12.26:
but, our system needs to support multi-roles completely;
so, what if a param is type multi-role(string, num)
and both those role's types have a zero-me operation?
then zero-me happens to both roles .
]
thus,
a part of the overhead of supporting mult-inheritance
is that the message sent to every object
includes not just the method name,
but also the datatype that the target obj
is expected to be
in case it has more than one self,
and thus more than one type .

. if a var is declared as a mult-role type,
then a modifying operation to that var
should act on every applicable self;
eg, in our previous example,
( var`zero-me ) would zero both selves of var,
the number and the string .
. in case we want to affect only one of the mult-role's selves,
there should be syntax for specifying the type:
eg, var`string.type`zero-me .
-- notice the array syntax might be intuitive
but there can be arrays of mult-role obj's,
eg, var#i`string.type`zero-me .

No comments:

Post a Comment