Re: sending a message from an initializer method
Re: sending a message from an initializer method
- Subject: Re: sending a message from an initializer method
- From: Andreas Grosam <email@hidden>
- Date: Fri, 14 Jan 2011 10:53:50 +0100
On Jan 14, 2011, at 1:29 AM, Richard Somers wrote:
> I often will do something like this.
>
> - (id)init
> {
> self = [super init];
> if (self) {
> [self prepare...];
> [self prepare...];
> [self prepare...];
> // etc...
> }
> return self;
> }
>
> The methods 'prepare...' are all private methods. The preparation code for one of my classes is over 300 lines with five individual prepare methods. Breaking it up like this keeps it organized, understandable, and aids in debugging and refactoring. It works very well.
unless a subclass accidentally overrides -prepareX: ...
The ubiquitousness of polymorphic methods and the lack of visibility rules in the runtime may make initializing of objects cumbersome, error prone and fragile.
So, just be careful.
If you don't want to have subclasses accidentally override your methods, you may want to prefix them:
@interface MyClass (Private) {
-(void) MyClass_init();
-(void) MyClass_foo:(id x);
}
- (void) awakeFromNib {
[self MyClass_init];
}
- (id) init {
self = [super init];
if (self) {
[MyClass_init];
}
return self;
}
Though, there is no guarantee.
Regards
Andreas_______________________________________________
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