Re: Subclassing Catch-22
Re: Subclassing Catch-22
- Subject: Re: Subclassing Catch-22
- From: Todd Blanchard <email@hidden>
- Date: Tue, 26 Apr 2005 16:22:05 -0600
then code the overridden methods like this:
- (NSString *)bindingKeyForTableColumnIdentifier: (NSString*)identifier
{
NSString* key = [super bindingKeyForTableColumnIdentifier: identifier];
if(!key)
{
NSArray *keys = [NSArray arrayWithObjects: @"name", @"notes", @"status", nil];
NSArray *identifiers = [NSArray arrayWithObjects: @"Name", @"Notes", @"Status", nil];
NSDictionary *keyForIdentifier = [dictionaryWithObjects: keys forKeys: identifiers];
key := [keyForIdentifier valueForKey: identifier];
}
return key;
}
On Tuesday, April 26, 2005, at 03:14PM, Todd Ransom <email@hidden> wrote:
>The code looks like this:
>
>- (NSString *)bindingKeyForTableColumnIdentifier: (NSString
>*)identifier {
>
> NSArray *keys = [NSArray arrayWithObjects: @"name", @"notes",
>@"status", nil];
> NSArray *identifiers = [NSArray arrayWithObjects: @"Name", @"Notes",
>@"Status", nil];
>
> NSDictionary *keyForIdentifier = [dictionaryWithObjects: keys forKeys:
>identifiers;
>
> return [keyForIdentifier valueForKey: identifier];
>}
>
>- (BOOL) tableViewAddColumnWithIdentifier: (NSString *)identifier {
>
> NSString *bindingKey = [self bindingKeyForTableColumnIdentifier:
>identifier];
>
> [create a table column, bind it, add it to a table]
>
>}
>
>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.
>
>Todd Ransom
>Return Self Software
>http://returnself.com
>On Apr 26, 2005, at 2:57 PM, Greg Titus wrote:
>
>>
>> On Apr 26, 2005, at 20:28, Todd Ransom wrote:
>>> I have a controller class that has methods like this:
>>>
>>> - (BOOL)doSomething;
>>> - (NSString *)getInformationRequiredToDoSomething;
>>>
>>> - (BOOL)doSomething {
>>>
>>> NSString *info = [self getInformationRequiredToDoSomething];
>>> ...
>>> }
>>>
>>> Which works fine until I subclass. In my subclass I would like
>>> doSomething to call super for a subset of possible actions. But when
>>> I call super it calls [self getInformationRequiredToDoSomething] and
>>> returns its own info, not super's.
>>
>> The pattern for this would be to make the superclass actually
>> implement:
>>
>> - (NSString *)internalInformationRequired;
>> {
>> ...
>> }
>>
>> - (NSString *)getInformationRequiredToDoSomething
>> {
>> return [self internalInformationRequired];
>> }
>>
>> - (BOOL)doSomething
>> {
>> NSString *info = [self internalInformationRequired];
>> }
>>
>> Then even if you override getInformationRequiredToDoSomething in a
>> subclass, the superclass's doSomething will get the original
>> information from the superclass. But like Ondra, I suspect that there
>> may be a better way to design this, if I had more information on what
>> you are trying to do.
>>
>> Hope this helps,
>> - Greg
>>
>>
>
> _______________________________________________
>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
>
>
_______________________________________________
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