[Drawkit] get tool controller?

Graham Cox graham.cox at bigpond.com
Tue Feb 17 15:25:14 PST 2009


On 18 Feb 2009, at 9:57 am, James Maxwell wrote:

> ignore this... I realized it would be simpler to use a notification.
>
> cheers,
>
> J.
>
>
> On 17-Feb-09, at 12:46 PM, James Maxwell wrote:
>
>> I need to get the tool controller from my DKObjectDrawingLayer -  
>> how do I do that?
>> It's a DKDrawingDocument-based app.
>


On a general note, sometimes the 'need' to do things like this can be  
a sign of something amiss in your design. A code smell, as some call  
it. In Model-View-Controller, model objects (such as the layer) don't  
generally need to have a deep knowledge of the controller(s), except  
typically to inform them in a general way that something changed. The  
inverse isn't true - controllers typically do have deep knowledge of  
the model objects they control.

You *can* get the controllers from a layer:

[[self drawing] controllers];

But note that this returns a set (list) of controllers. In most  
designs there will probably be only one, but you can't assume (and DK  
sometimes inserts temporary controllers into this list for some  
operations). Being a set, the list is unordered. Again this tells you  
that no controller is any more or less important than any other.  
Getting a specific controller requires more knowledge, such as which  
view it is associated with, by which time you've well and truly broken  
MVC.

If you want to tell me what you're trying to do, I can advise further.

--Graham.


More information about the Drawkit mailing list