4 Oct 2004 14:50
Re: Type parameters for Publisher
Martin Odersky <martin.odersky <at> epfl.ch>
2004-10-04 12:50:11 GMT
2004-10-04 12:50:11 GMT
Mathias Weyel <Mathias.Weyel <at> josquin.org> writes:
> Hello!
>
> I want to use the class Publisher as mixin to propagate change events
> to subscribers. Here's the code:
>
> class ToolManager with Publisher[ToolChangeEvent, ToolManager] {
>
> private var _actualTool : Tool = SelectionTool();
> def actualTool = _actualTool;
> def actualTool_=(t : Tool) = {
> this publish new ToolChangeEvent(actualTool, t);
> _actualTool = t;
> }
>
> }
>
> The problem now is, that I would like to have the ToolManager to be
> just an object definition, but how can this be accomplished? If I just
> replace the "class" with "object", I have no type to give the
> publisher as second type parameter.
You do have a type. Singleton types come to the rescue here:
object toolManager { ... }
class ToolManager with Publisher[ToolChangeEvent, toolManager.type] {
...
}
Hope this helps
-- Martin
RSS Feed