best practices for object instance initialization
best practices for object instance initialization
- Subject: best practices for object instance initialization
- From: Stuart Malin <email@hidden>
- Date: Fri, 21 Mar 2008 10:07:33 -1000
I have a class (a subclass of NSObject) that requires several
parameters to be properly initialized. I have a -(id)
initWithParams... method defined.
I can't have -init invoke -initWithParams (as a designated
initializer) because the object instance wouldn't be set up
properly. I am wondering what is the best practice regarding -(id)
init in such a case.
1) Do I just let -init dangle (so to speak)? and then if I ever
forget that the object needs special initialization and instead call -
init, the code will end up failing down the line somewhere where
those initialization parameters matter...
2) Do I define a -(init) method and have it throw an exception? so
that I'll find out right away if some code invokes -init rather than -
initWithParams....
3) Is there some way to tell the compiler to ignore the
superclasses's -init for the subclass so that I get a compile time
error? This would be my preferred outcome.
Thanks in advance for your thoughts,
--Stuart
_______________________________________________
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