Inheritance/Multiple: Difference between revisions

(Removed C omission flag)
Line 1,221:
but a call to the object's metaobject
that returns the method resolution order for this type.
 
=={{header|Phix}}==
Needs 0.8.1+
===inheritance===
The programmer is expected to assume complete responsibility (away from the compiler) for checking/resolving any conflicts.
<lang Phix>
class Camra
string name = "nikkon"
end class
class Mobile
-- string name = "nokia" -- oops!
string mane = "nokia" -- ok!
end class
class CamraPhone extends Camra,Mobile
procedure show() ?{name,mane} end procedure
end class
CamraPhone cp = new()
cp.show()</lang>
{{out}}
<pre>
{"nikkon","nokia"}
</pre>
===composition===
The programmer is expected to assume complete responsibility for invoking new() appropriately.<br>
The example below shows four different approaches to invoking all the new() that are needed (one pair commented out).<br>
Note that invoking new() inside a class definition creates shared references to a single instance.<br>
The compiler demands to be explicitly told what the inner/inlined new() on cp2 are actually for.
<lang Phix>class Camera
public string name = "nikkon"
end class
class MobilePhone
public string name = "nokia" -- (clash no more)
end class
class CameraPhone
-- Camera c = new()
-- MobilePhone m = new()
public Camera c
public MobilePhone m
procedure show() ?{c.name,m.name} end procedure
end class
Camera c = new({"canon"})
MobilePhone m = new()
CameraPhone cp1 = new({c,m}),
cp2 = new({new("Camera"),new("MobilePhone")}),
cp3 = new() -- (internal/shared/NULL c,m)
cp3.c = new() -- (obviously c must be public)
cp3.m = new({"LG20"}) -- "" m "" ""
cp1.show()
cp2.show()
cp3.show() -- crashes without internal/above new()</lang>
{{out}}
<pre>
{"canon","nokia"}
{"nikkon","nokia"}
{"nikkon","LG20"}
</pre>
 
=={{header|PicoLisp}}==
7,805

edits