#1232 mixin question

zyhong Sat 25 Sep 2010

a little confused about the mixin:

this won't compile:

mixin A 
{
  Str s()
}

this compile:

mixin A 
{
  abstract Str s()
}

It makes sense. I guess it is the rule to use abstract keyword. However, in Service.fan:

const mixin Service{
...
  This install()
...
}

They all compile very well. Also, it seems that both SqlService and WispService does not implement the abstract method in service mixin at all. What do i miss?

andy Sat 25 Sep 2010

Since mixins may contain concrete methods, you do need to specify the abstract modifier:

mixin A
{
  Str foo() { return "hi!" }
  abstract Str bar()
}

All the sys pod types are a special case because they are implemented in the runtime's native language (Java, C#, JavaScript, etc). So those fan source files serve only to annotate the type and provide documentation.

zyhong Sat 25 Sep 2010

got it. thanks, andy

DanielFath Sat 25 Sep 2010

The reason your example doesn't compile is that you haven't provided implementation. As for the service and few other system classes seem to have special implementations which for some reason aren't shown there (andy explained this). This has nothing to do with it. If you tried out

mixin B
{
  This something() {return this}
}

you'd see that it works regardless of This return-type.

By the way (and I mean no disrespect) indent your all your code by two or more spaces, that way the renderer won't make code come off so hideously mangled.

zyhong Sat 25 Sep 2010

thanks for the info, DanielFath. finally get the trick for code block:)

andy Sat 25 Sep 2010

@zyhong - Fandoc in all its glory: /doc/fandoc/pod-doc.html (there is also an oft missed cheatsheet to the right of the comment editor).

Login or Signup to reply.