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> |
<lang elena>singleton CameraFeature |
||
{ |
{ |
||
cameraMsg |
cameraMsg |
||
= "camera" |
= "camera"; |
||
} |
} |
||
class MobilePhone |
class MobilePhone |
||
{ |
{ |
||
mobileMsg |
mobileMsg |
||
= "phone" |
= "phone"; |
||
} |
} |
||
class CameraPhone |
class CameraPhone : MobilePhone |
||
{ |
{ |
||
dispatch => CameraFeature |
dispatch() => CameraFeature; |
||
} |
} |
||
public program |
public program() |
||
{ |
|||
[ |
|||
var cp := |
var cp := new CameraPhone(); |
||
console |
console.writeLine(cp.cameraMsg); |
||
console |
console.writeLine(cp.mobileMsg) |
||
}</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"; |
||
} |
} |
||
singleton CameraPhone |
|||
{ |
{ |
||
new = |
new() = new MobilePhone().mixInto(new CameraFeature()); |
||
} |
} |
||
public program |
public program() |
||
{ |
|||
[ |
|||
var cp := CameraPhone |
var cp := CameraPhone.new(); |
||
console |
console.writeLine(cp.cameraMsg); |
||
console |
console.writeLine(cp.mobileMsg) |
||
}</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |