Re: Forwarding messages to another class
Re: Forwarding messages to another class
- Subject: Re: Forwarding messages to another class
- From: Quincey Morris <email@hidden>
- Date: Sat, 06 Jun 2015 22:15:42 +0000
On Jun 6, 2015, at 14:35 , Cosmo <email@hidden> wrote:
>
> Can somebody explain to me why I’m getting this different behavior. Is there anything I can do to achieve my goal?
The most likely immediate reason is that the class returned by '[self classToUseForBackend]’ doesn’t actually implement a method called ‘errorMessageForCode:’. If you think it does, check the spelling and capitalization of the method name in the subclass.
However, the code fragments you show here don’t make any sense. Class methods in Obj-C (methods with a ‘+’) have inheritance like instance methods. So, if a subclass implements (say) ‘logout’, execution is never going to reach the superclass implementation. If a subclass *doesn’t* implement (say) ‘errorMessageForCode:’, you’re going to get an infinite loop.
Furthermore, if the subclass method happens to call the ‘super’ method, then you will again end up with an infinite loop.
If your intention is to have a class hierarchy where the base class defines methods that the subclass must implement — that is, where the base class has abstract methods — there are two straightforward ways:
1. Define the base class method but don’t do anything in it, except possibly to cause an exception:
+ (void) logout {
NSAssert (NO, @“Subclass responsibility”);
}
2. Use a protocol instead of a base class:
@protocol BaseClassProtocol
+ (void) logout;
@end
_______________________________________________
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