On Jan 20, 2009, at 11:52 PM, eduard aylon wrote:
Hello Scott, thanks for your reply. Actually now I realise that my question was incorrect... too tired due to a project deadline. My question, actually, should have been about polymorphism and not inheritance. What I want is that having a base class Point and another class Point2D which inherits from Point, that I can define a Point p, that could morph and become a Point2D. Or in other words, that an UGen, can become a SinOsc.
Is that possible?
Still not sure I completely understand -- you can assign a higher class to a reference defined as a subclass, and then you can upcast that. e.g. class Foo { fun void f() { <<< 1 >>>; } } class Bar extends Foo { fun void f() { <<< 2 >>>; } } new Bar @=> Foo @ foo; foo $ Bar @=> Bar @ bar; foo.f(); bar.f(); Produces: 2 :(int) 2 :(int) There's no real "morphing" in there though. Once a class is instantiated it stays the same type, it's just that it can have a handle that refers to it that's a base-class or one of its own type. -Scott