[chuck-users] parent and children classes (I meant polymorphism)

eduard aylon eduard.aylon at gmail.com
Tue Jan 20 19:38:46 EST 2009


Scott,
this is exactly what I want to do. I was getting confuse myself in a  
very stupid way, but got the answer now. Thanks a lot

eduard


On Jan 21, 2009, at 12:10 AM, Scott Wheeler wrote:

>
> 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
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users



More information about the chuck-users mailing list