Re: Cocoa coding style (was Re: Did I reinvent the wheel?)
Re: Cocoa coding style (was Re: Did I reinvent the wheel?)
- Subject: Re: Cocoa coding style (was Re: Did I reinvent the wheel?)
- From: Jens Alfke <email@hidden>
- Date: Sat, 10 May 2008 21:47:36 -0700
On 10 May '08, at 7:29 PM, Western Botanicals wrote:
The reason for using the singleton method was to ensure that I never
have more than one cache or database access object. Having more than
one cache or database access object could lead to having the same
data pulled from the database into more than one object.
What if you later find you need to connect to two databases? This
actually happened to me in a project. Originally I had made the DB
object a singleton, but then later it turned out we had to be able to
migrate data from an older database, which meant being able to open a
second DB object on that database to read the data out of it, so I had
to change a bunch of code around.
Or what if you need to have two semi-independent engines in the same
process that each work on the same database, but in different
sessions / transactions? This can happen too, e.g. in a web server
handling concurrent requests*.
—Jens
* This really happens, and can have major repercussions. Ruby doesn't
work well inside Apache because, in part, the interpreter has global
state so it can't be instantiated multiple times in a sort of
mod_ruby. This in turn makes it nearly impossible to run Rails well in
a shared-hosting environment where you can't run your own server
process.Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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