Hi All,

I came across this code and was wondering if this is normal practice and/or considered good coding style.

Given two classes ClassX and ClassY:

@interface ClassX
{
ClassY  mClassY;
}

@property (nonatomic,retain,readonly)           ClassY*         mClassY
@end

@interface ClassY
{
int             mClassYValue;
}

@property (nonatomic,retain,readonly)           ClassY*         mClassY

@end

@implementation ClassX

-(ClassY*) mClassY
{
if (mClassY == nil)
        {
        mClassY [[ClassY alloc] initWithData:someData]:
        }
return mClassY;
}


Then later in another method of ClassX, I found the following code:

self.mClassY. mClassYValue = someValue;

Before this statement is executed, self. mClassY is nil. When it is executed it causes the "mClassY" method to be called which allocates the Class and sets the Variable.

Is this normal? Looking at the code it seems hard to see what is going on, Surely it would be better practice to have an init method that does this? e.g.

self.mClassY = [[alloc] initWithData: initWithData:someData]

Just trying to figure out the best approach for something like this.

Thanks in Advance
Dave













@end



_______________________________________________

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