static vs non-static. Recommendation needed.
static vs non-static. Recommendation needed.
- Subject: static vs non-static. Recommendation needed.
- From: Тимофей Даньшин <email@hidden>
- Date: Mon, 13 Apr 2009 12:13:28 +0400
Hello.
A foreword:
In my application I need to allow the user to create a database. So i
display a dialogue panel, collect all the necessary information about
the db to be created and create a "DatabaseInfo" object. Then i pass
that DatabaseInfo object to the DatabaseCreator to actually create the
needed database. I want the DatabaseCreator to "return" an sqlite3
pointer.
And here is my dilemma:
As i don't need that DatabaseCreator to exist for a long time i
thought it better to make it completely static. Sorry if the
terminology is wrong, but what i mean is: it cannot be initialized, it
has no instance variables, it has no instance methods, all it has is
one public class method: + (sqlite3 *) createDbaseWithDatabaseInfo:
(DatabaseInfo *) dbInfo;
However, that proves not very convenient, as i need to break up the
logic of that class into individual steps and I end up passing a lot
of things from one method to another.
Is it all right to init an object just to dealloc it in the next line
(or create an autorelease object using a convenience method for that
matter)? I mean, if i made it non-static, i would have something like
this in the class that uses it:
DatabaseCreator *dbc = [DatabaseCreator creatorWithDBInfo: dbInfo];
sqlite3* database = [dbc database]; // and dbc would no longer be used.
Or is it better to put up with the inconveniences of having that thing
static?
Thank you in advance,
Timofey.
_______________________________________________
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