Re: question about -init methods
Re: question about -init methods
- Subject: Re: question about -init methods
- From: Rob Ross <email@hidden>
- Date: Fri, 7 Jul 2006 12:22:34 -0700
On Jul 7, 2006, at 10:25 AM, Matt Neuburg wrote:
On Fri, 7 Jul 2006 18:54:59 +0530, Vinay Prabhu
<email@hidden> said:
It can be done, provided the alloc should not be called again.
Lots of things *can* be done. The question is, *should* it?
(Example: you *can* write a dealloc method without calling super
dealloc.
But don't!)
I think what I'd like to hear the OP focus on is *why* he thinks he
might
need to do this. Since an instance "re-initialized back to its initial
state" would be effectively the same as a completely new instance,
why not
use a completely new instance? What do you think "re-
initialization" would
get you? m.
Well I'm thinking more in terms of how things work in the Obj-C world
as opposed to specific use cases. It's a new concept for me that
allocation API for the object's memory is a distinct step different
from initialization; coming from the Java world both happen at the
same time via the object's constructor, and by design there is no way
to re-call an object's constructor in Java.
(Also, I am used to having my own private init() methods in Java
classes, called from my constructor, to organize my object's
initialization code. I have to find a new name for those methods
now!! What do other people call their helper methods that are called
from the -initXXX methods that help the initializer perform its
initialization code?)
The only case I can think of at the moment for re-use of an
initializer is where object creation is an expensive step in time or
memory, and you might want to re-use an existing instance and just
reset it back to its initial state. For these cases having a -(void)
reset method called by -initXXX as Bill Bumgarner suggests sounds
like a solution to this issue without having to call the initializer
again.
Rob
-----Original Message-----
From: cocoa-dev-bounces+vinayprabhu=email@hidden
[mailto:cocoa-dev-bounces
+vinayprabhu=email@hidden]On
Behalf Of Rob Ross
Sent: Friday, July 07, 2006 2:22 PM
To: email@hidden
Subject: question about -init methods
Is is mandatory that Objective-C class instances have their
designated initializer called only once? Can you design an
initializer so that it can be called again to re-initialize the
instance back to its initial state, or is that considered bad form?
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden