delegates?

Discussion in 'Mac Programming' started by liptonlover, Jun 1, 2008.

  1. liptonlover macrumors 6502a

    Joined:
    Mar 13, 2008
    #1
    I'm working through Hillegass' book, and it's bringing up delegates. The problem is, it never defines what a delegate is and because of it I can't complete one of the exercises. Can anyone please help?
     
  2. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #2
    Delegates are objects that implement all or part of an 'informal protocol', and attach themselves as the delegate object for something else (see the -delegate and -setDelegate: methods).

    Each object that can have a delegate will use it differently, and have a different informal protocol. NSTableView and NSApplication can both have delegates for example, but each one expects its delegate to implement different methods.

    If you want to know what delegate methods a particular class supports, you will need to look at the class reference documentation for that class.
     
  3. aLoC macrumors 6502a

    Joined:
    Nov 10, 2006
    #3
    It's a way of customizing one of Apple's classes. Basically you make your own object and tell Apple's object about it. Then Apple's object calls yours at certain times, thus *in effect* you have added your code to Apple's object.

    In normal OO you would subclass a class to add your code to it. This is just a different way of doing it (a "design pattern") that gives the same effect without the need to subclass.
     
  4. cmaier macrumors G3

    Joined:
    Jul 25, 2007
    Location:
    California
    #4
    I think he defines what a delegate is, but does so by calling it a "helper class." Then he switches to referring to it as a delegate later on.
     
  5. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #5
    Delegates have one advantage, you can have one delegate object for multiple other objects. In some cases, it is useful.
     
  6. liptonlover thread starter macrumors 6502a

    Joined:
    Mar 13, 2008
    #6
    yes he does have a section about helper objects... that makes sense. Thanks everyone!
     

Share This Page