On Apr 2, 2010, at 13:48, Dave wrote:

> 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]

It's perfectly normal for a class to defer creating the contents of an instance 
variable until it's needed. (There's no way an client of the class can tell the 
difference.) However, there's not much point in doing so *unless* creating it 
is so expensive in terms of memory or performance that there's an actual 
benefit in doing the deferring.

Incidentally, your suggested line of code above doesn't follow current best 
practices (aside from the typo in the 'alloc' invocation). It would be placed 
in ClassX's -init method, and the current fashion (for good technical reasons) 
in an -init method is *typically* to set the instance variable directly:

        mClassY = [[ClassY alloc] initWithData: initWithData:someData];

instead of using the setter as you proposed. Also, your version would produce a 
memory leak.


_______________________________________________

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