Re: Replacing objects
Re: Replacing objects
- Subject: Re: Replacing objects
- From: WT <email@hidden>
- Date: Tue, 23 Dec 2008 00:03:45 +0100
Hi Dimitri,
you can make use of the so-called Proxy design pattern. Write all your
code in terms of a proxy object that stands in for the real thing.
Then your code doesn't have to know, or care, whether the object
you're manipulating comes from the server or is local. It's the
responsibility of the proxy object's class to do the swapping that you
want.
In other words, you have something like this:
Ptr A -> proxy1
Ptr B -> proxy1
Ptr C -> proxy1
and those pointers never stop pointing to proxy1. Proxy1, however, has
an internal object that it can swap with something else as needed. Of
course, the proxy object's class has to share the same interface as
the class of the objects it represents so that your code doesn't need
to know whether it's dealing with a proxy or with the real thing.
For more details, look here:
http://en.wikipedia.org/wiki/Proxy_pattern
Wagner
Hey guys, I'm fairly new to cocoa development here, so please bear
with me. Is it possible to replace an object with another object so
that all pointers to that object now point to the new object? In
other words:
Ptr A -> object1
Ptr B -> object1
Ptr C -> object1
I want to replace object1 with another object (of the same type), so
that all my pointers now point to object2. I realize that I could
manually replace all of the internal data in the object, thus
leaving the pointer intact, but I was hoping that there would be an
easier way.
The reason I'm trying to do this is that I have a number of
NSMutableArray's throughout my application whose contents are based
off a database on a server. Periodically, the user searches the
database, which returns a list of objects. Some of these objects the
client already has, and in that case I would like to replace the
local object with the one I've created via the server. I've
implemented an NSDictionary that holds all of the objects that have
come in from the server, and each NSMutableArray points to those
same objects (they are all subsets of the main list). This works
fine except for in the case where an existing object comes in from
the server. I'd like to be able to replace the original object with
my new one and retain all of it's pointers.
Thanks for the help,
Dimitri
_______________________________________________
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