Inheritance/Multiple: Difference between revisions
Content added Content deleted
Mercerenies (talk | contribs) (Latitude language added) |
(Added Wren) |
||
Line 1,465: | Line 1,465: | ||
superclass Camera MobilePhone |
superclass Camera MobilePhone |
||
}</lang> |
}</lang> |
||
=={{header|Wren}}== |
|||
Wren does not support either multiple inheritance or interfaces. |
|||
However, multiple inheritance can be simulated by inheriting from a single class and then embedding objects of other classes and wrapping their methods. |
|||
<lang ecmascript>class Camera { |
|||
construct new() {} |
|||
snap() { System.print("taking a photo") } |
|||
} |
|||
class Phone { |
|||
construct new() {} |
|||
call() { System.print("calling home") } |
|||
} |
|||
class CameraPhone is Camera { |
|||
construct new(phone) { _phone = phone } // uses composition for the Phone part |
|||
// inherits Camera's snap() method |
|||
// Phone's call() method can be wrapped |
|||
call() { _phone.call() } |
|||
} |
|||
var p = Phone.new() |
|||
var cp = CameraPhone.new(p) |
|||
cp.snap() |
|||
cp.call()</lang> |
|||
{{out}} |
|||
<pre> |
|||
taking a photo |
|||
calling home |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |