[comp.sys.next] Delegates, Outlets, idea

johner@portia.Stanford.EDU (John Lynch) (05/25/90)

In article <266@atncpc.UUCP> bruce@atncpc.UUCP (Bruce Henderson) writes:

>of them have what are labeled "Delegate Methods".  These methods 
>are to be implemented by that object's delegate(as we saw above, where
>a subclass of window implemented one of a text object's delegate
>methods).  Often you will wnat ot make an object it's own delegate.
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
>This is often the case with windows.  This way you can limit the 
>dimentions that the user can resize the window to by implementing 
>the window delegate method windowWillResize:toSize: .  This is how
>the Workspace Browser limits you to resize only widths that are 
>multiples of the width of one browser bay.
  
  I was always under the impression that the point of the delegate was to
give the developer the ability to give a certain set of his windows
identical high-level behavior,without redefining or subclassing anything.

  In other words, without having to subclass window or anything, I can just
set the delegate of each document window to a certain object I define,
when I create the window.

 The delegate object receives messages like windowWillClose:sender, with sender
being whichever window is closing. You can then do [sender isDocEdited]to
check if you need to save and such.  So all of your windows behave the same
without subclassing window. And, although I can't think of why you would
want to do this, you could define a bunch of delegate objects and switch
them for various windows to get different behavior at different times.
  Or, to use your example, I define an object to be all of my scrollTexts'
delegate. Then, upon receiving a textWasEdited or whatever message, I can
query the sender view to find out its window, then just send the
window a docEdited message.

  Whatever, I don't mean to second-guess, I just thought that was how they
were supposed to be used.  I guess the point is that you get the flexibility
to do it whichever way you want.  It's probably just a matter of style anyway,
since you get the same result by subclassing window. I think it does add some
overhead,though, since each window instance must have the method to save
dirty windows,etc.,versus just the delegate object having it.
  Just a thought.
John Lynch
johner@portia