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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to