[Grace-core] mixins..

James Noble kjx at ecs.vuw.ac.nz
Sun Jul 22 21:23:01 PDT 2012


I was just teaching a tutorial about the Decorator Pattern
and mentioned our old friend the mixing.  So, should
Grace support the likes of 

class Mixin.new<C> {
  inherits C
} 

or alternatively

class Mixin.new(o) {
 inherits o 
}

for what it's worth, the following works in minigrace:

> method mix(o) {
>     return object {
>             inherits o
>             method foo {print ("FOO!"); super.foo}
>     }
> }
> 
> class Mixin.new(o) {
>     inherits o
>       method foo {print ("FOO!"); super.foo}
> }
> 
> 
> def b = object {
>     method foo {print "BAR"}
>     }
> 
> 
> b.foo
> mix(b).foo
> Mixin.new(b).foo


More information about the Grace-core mailing list