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: Richard Somers <email@hidden>
- Date: Thu, 13 Jan 2011 17:29:58 -0700
On Jan 12, 2011, at 4:41 AM, Luc Van Bogaert wrote:
I would like to implement that algorithm in a seperate method,
instead of writing it directly in the initializer. Is that OK, and
could I then message "self" in the initializer like:
- (id) init
{
self = [super init];
if (self) {
var1 = ...;
var2 = ...;
var3 = [self computerVar3With:var1:var2];
}
return self;
}
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.
--Richard Somers
_______________________________________________
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