• 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: Advice On Subclass vs. Delegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice On Subclass vs. Delegate


  • Subject: Re: Advice On Subclass vs. Delegate
  • From: Greg Guerin <email@hidden>
  • Date: Sat, 14 Nov 2009 12:49:12 -0700

s.ross wrote:

How it's implemented now is that I have a separate controller for each field and the NSTextField delegates to that controller because for each character, I need to:

- dup-check and possibly count
- change a label to show the count and any dup alerts
- watch for control:completions:forPartialWordRange and provide a custom list


This seems like boneheaded code duplication, when what I really want is a more general class that can be told:

Hey! This NSTextField needs to be watched for dups, so split on [\s*,\s*] and each time a new word shows up, call my method:

theresANewWord:count withDuplicates:dups.

That suggests to me that subclassing NSTextField and allowing a single controller to register a callback would be the right way to go, but I'm struggling with how to specify *which* text field and whether my design idea is even sound.

Sounds to me like you need a small class hierarchy of delegate classes. Don't make each text-field point to a single controller. Assign each textfield a delegate object (instance of a specific delegate subclass) appropriate to the handling that field needs. The delegate objects may be coupled to the overarching controller for the "theresANewWord" functionality or the label-changing feature.


  -- GG

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSPopUpButton submenu's
  • Next by Date: Re: controlTextDidEndEditing and buttons...
  • Previous by thread: Re: Advice On Subclass vs. Delegate
  • Next by thread: iPhone: Having a touch point want to find layer it is in
  • Index(es):
    • Date
    • Thread