Martin Odersky | 4 Oct 2004 14:50
Picon
Picon
Favicon

Re: Type parameters for Publisher


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


Gmane