Inheritance/Multiple: Difference between revisions

Content added Content deleted
(Added Rust)
Line 324: Line 324:
=={{header|Elena}}==
=={{header|Elena}}==
ELENA only permits inheritance from one parent class. However, mixins are supported
ELENA only permits inheritance from one parent class. However, mixins are supported
<lang elena>class CameraFeature =
<lang elena>singleton CameraFeature
{
{
cameraMsg
cameraMsg
= "camera".
= "camera";
}.
}
class MobilePhone
class MobilePhone
{
{
mobileMsg
mobileMsg
= "phone".
= "phone";
}
}
class CameraPhone :: MobilePhone
class CameraPhone : MobilePhone
{
{
dispatch => CameraFeature.
dispatch() => CameraFeature;
}
}
public program
public program()
{
[
var cp := CameraPhone new.
var cp := new CameraPhone();
console writeLine(cp cameraMsg).
console.writeLine(cp.cameraMsg);
console writeLine(cp mobileMsg).
console.writeLine(cp.mobileMsg)
]</lang>
}</lang>
Alternatively a group object may be created
Alternatively a group object may be created
<lang elena>import system'dynamic.
<lang elena>import system'dynamic;


class CameraFeature
class CameraFeature
{
{
cameraMsg
cameraMsg
= "camera".
= "camera";
}
}


Line 360: Line 360:
{
{
mobileMsg
mobileMsg
= "phone".
= "phone";
}
}


class CameraPhone =
singleton CameraPhone
{
{
new = MobilePhone new; mixInto(CameraFeature new).
new() = new MobilePhone().mixInto(new CameraFeature());
}.
}


public program
public program()
{
[
var cp := CameraPhone new.
var cp := CameraPhone.new();


console writeLine:(cp cameraMsg).
console.writeLine(cp.cameraMsg);
console writeLine:(cp mobileMsg).
console.writeLine(cp.mobileMsg)
]</lang>
}</lang>


=={{header|Factor}}==
=={{header|Factor}}==