• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: OBJ-C question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OBJ-C question


  • Subject: Re: OBJ-C question
  • From: Sherm Pendley <email@hidden>
  • Date: Sat, 17 Apr 2004 13:37:01 -0400

On Apr 17, 2004, at 1:13 PM, Ondra Cada wrote:

On 17.4.2004, at 18:59, Sherm Pendley wrote:

You could add default implementations of your methods as a category to NSObject. That would also take care of the warnings for informal protocols.

That's exactly what you DON'T WANT to. That's the whole point of informal protocols--let the class to implement the method or not, and behave accordingly.

I'm confused - your advice is seemingly contradictory to Apple's practice. Looking at AppKit headers such as NSWindow.h, NSOutlineView.h, and NSBrowserView.h, I see all of the delegate and/or data source methods that are relevant to each class added to NSObject as a category.

This pattern, to me, seems worth following - the default method that's added to NSObject does nothing, and users who provide a delegate and/or data source class can override this behavior as they wish. And even if they don't, no warnings about unrecognized methods are produced.

There's also efficiency to consider - without a default implementation, you have to call respondsToSelector: before each call to a data source method. You couldn't simply call it in setDataSource: because the method could be added to the class after the data source object has been assigned. Not only would this clutter up your code, it would introduce a bottleneck in what is usually a frequently-called time-critical method.

What am I missing? The only drawback I can think of is polluting NSObject with a bunch of do-nothing default methods, but with carefully-named methods that's hardly a critical problem.

sherm--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: OBJ-C question
      • From: John Randolph <email@hidden>
    • Re: OBJ-C question
      • From: Dustin Voss <email@hidden>
    • Re: OBJ-C question
      • From: Shaun Wexler <email@hidden>
    • Re: OBJ-C question
      • From: Ondra Cada <email@hidden>
    • Re: OBJ-C question
      • From: Kay Roepke <email@hidden>
References: 
 >OBJ-C question (From: "Mike R. Manzano" <email@hidden>)
 >Re: OBJ-C question (From: Ondra Cada <email@hidden>)
 >Re: OBJ-C question (From: "Mike R. Manzano" <email@hidden>)
 >Re: OBJ-C question (From: Ondra Cada <email@hidden>)
 >Re: OBJ-C question (From: Sherm Pendley <email@hidden>)
 >Re: OBJ-C question (From: Ondra Cada <email@hidden>)

  • Prev by Date: Current mouse screen?
  • Next by Date: Using POSIX threads with Cocoa?
  • Previous by thread: Re: OBJ-C question
  • Next by thread: Re: OBJ-C question
  • Index(es):
    • Date
    • Thread