• 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: Subclassing Catch-22
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing Catch-22


  • Subject: Re: Subclassing Catch-22
  • From: "Seth A. Roby" <email@hidden>
  • Date: Tue, 26 Apr 2005 16:31:29 -0700

On Apr 26, 2005, at 2:17 PM, Todd Ransom wrote:
The theory was that subclasses would override both methods, returning the appropriate key to bind to and implementing whatever specifics were required for the table column (popup button cells, date formatters, etc.).

It all worked fine except I wanted the subclasses to defer to super for columns shared by all views.

I might just be oversimplifying things here, but it seems to me that the following pattern works fine:


@implementation Superclass
- (NSDictionary*)bindingKeysForTableColumns {
return [NSDictionary dictionaryWithKeysAndValue:@"name", @"Name",
@"notes", @"Notes",
@"status", @"Status", nil];
}
- (NSString*)bindingKeyForTableColumnIdentifier:(NSString*)identifier {
return [[self bindingKeysForTableColumns] valueForKey:identifier];
}
- (BOOL)tableViewAddColumnWithIdentifier:(NSString*)identifier {
NSString* bindingKey = [self bindingKeyForTableColumnIdentifier:identifier];
//create the column
}
@end


@implementation Subclass
- (NSDictionary*)bindingKeysForTableColumns {
NSMutableDictionary* retval = [[[super bindingKeysForTableColumns] mutableCopy] autorelease];
[retval setKey:@"newKey" forValue:@"newIdentifier"];
return retval;
}
- (BOOL)tableViewAddColumnWithIdentifier:(NSString*)identifier {
BOOL retval = [super tableViewAddColumnWithIdentifier:identifier];
if (!retval) {
//the superclass didn't do it for us, so we've gotta do it ourselves...


NSString* bindingKey = [self bindingKeyForTableColumnIdentifier:identifier];
//create the column
retval = YES;
}
return retval;
}


This allows subclasses to depend on the superclass to handle the common cases, and to augment those cases with whatever key/identifiers they want to, and then handle those cases when the superclass doesn't do it already.

The "pattern" here is to allow the dictionary to be modifiable outside of the -bindingKeyForTableColumnIdentifier method, as was suggested elsewhere in the thread.

Seth A. Roby The Amazing Llama < mail or AIM me at tallama at mac dot com>
"Life is like an exploded clown. It's really funny until you figure out what just happened."

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Subclassing Catch-22 (From: Todd Ransom <email@hidden>)
 >Re: Subclassing Catch-22 (From: Marco Scheurer <email@hidden>)
 >Re: Subclassing Catch-22 (From: Todd Ransom <email@hidden>)
 >Re: Subclassing Catch-22 (From: Greg Titus <email@hidden>)
 >Re: Subclassing Catch-22 (From: Todd Ransom <email@hidden>)

  • Prev by Date: Re: ADC Select Membership
  • Next by Date: Re: Subclassing Catch-22
  • Previous by thread: Re: Subclassing Catch-22
  • Next by thread: Re: Subclassing Catch-22
  • Index(es):
    • Date
    • Thread