From: David M. C. <da...@da...> - 2005-05-10 05:59:09
|
On Mon, May 09, 2005 at 08:33:58PM -0500, Ian Bicking wrote: > >class Proxy(object): > I'm not entirely clear what this is for. Uniform object access. >At first I thought it was a > kind of optimistic lock, but not so. How would you actually use this? In some ORMs or OODBs objects start out as 'unmanaged' or 'lonely', and then you save them. For example, in IndexedCatalog catalog = shelf[Customer] # create an 'empty' object obj = Customer() # get some values for display (values are None at this point, of course) name = obj.name phone = obj.phone # set some values obj.name = 'Bob' # obj is 'lonely' up to this point catalog.insert(obj) So the obj doesn't have to meet integrity constraints until you actually insert it, but you can still use it the same way you would use a 'managed' object. The idea of the Proxy is to mimic this behavior: obj = Proxy(Customer) # pass this single object off to my input handler # get some values for display name = obj.name phone = obj.phone # set some values obj.set(**data) Though the above simple-minded proxy is not really up to the task when you need to create foreign key objects first. Essentially Proxy just encapsulates logic like # get some values for display foo = getattr(obj, 'foo', None) # obj may be None baz = getattr(obj, 'baz', None) # now do something with input values if not obj: obj = soClass(**data) else: obj.set(**data) Dave Cook |