Re: Keeping track of state in Cocoa
Re: Keeping track of state in Cocoa
- Subject: Re: Keeping track of state in Cocoa
- From: Wim Lewis <email@hidden>
- Date: Wed, 1 Dec 2010 15:43:00 -0800
On 1 Dec 2010, at 3:31 PM, Jon Sigman wrote:
> I have a message receiver which manages a number of TCP-connected processes (100
> or so). However, I need to keep track of the state of each connected process
> (registered, busy, waiting, etc) to know what operations are 'legal' or
> appropriate for dealing with each one.
>
> Is there any construct, design pattern, object, etc inherent in Cocoa or OSX
> that is used for this kind of thing, or do people 'roll their own' with some
> sort of ad hoc table, struct, etc?
The first approach I'd consider would be to encapsulate all the state needed for dealing with a given connection into an object, and use an NSDictionary (or CFDictionary) to find the instance associated with a connection when needed.
Another common pattern is to move the objects between different collections depending on their state--- you might have an NSArray of idle connections, say, and pull one out when you need to use it (like a freelist), putting it into some other collection while it's active.
_______________________________________________
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