Title: Composite data structures: Advice needed for creating the model structure Post by: olist on February 27, 2009, 03:43:09 Hi everyone,
I'm working on a AS3 game using PureMVC and got literally stuck on the middle of the road. Any help or advice is highly appreciated, maybe I'm completely on the wrong track... On the model side I have a number of drivers and each driver has a list of cars he has created before. Drivers and cars can appear in different views at the same time. I have separate VOs for cars and drivers and service delegates for server communication. When requesting a driver, I only know its unique ID. The service responds some attributes and a list of assigned car IDs. After parsing the data I request lightweight instances of the referenced cars based on their IDs. At the moment, every driver VO is assigned to its own DriverProxy instance, car VOs are accessed via CarProxy instances respectively. I access those proxies via the unique driver and car IDs like this: var proxy:CarProxy = facade.retrieveProxy(car.id) as CarProxy; I'm stuck in the question of how to model the relationship between a driver and its cars:
I hope I explained the problem clearly enough, in my head things are getting quite mixed up. Thanks for your advice, Cheers, Oliver Title: Re: Composite data structures: Advice needed for creating the model structure Post by: puremvc on March 01, 2009, 08:27:58 I think it might be easier if you had one CarsProxy, which held an array of cars. It could have add, get and remove car methods. When a driver is retrieved, you could request all the associated cars in one call keeping the result in one proxy. So you avoid the hassle of deciding when and how to remove unneeded proxies.
Sticking with your existing setup, you need to know when a given Proxy is no longer needed, when claims to it come from actors that don't know each other. So you could add a usage count to the proxy and whenever something retrieves it, bump up the count and when done, decrement it. When its decremented to zero, go ahead and have the Proxy remove itself. There is a utility called PGProxyReservation listed in the 'Public Apps, Demos and Utilities' area of these forums that I believe is geared to this sort of scenario. You might want to scope that out before implementing. -=Cliff> Title: Re: Composite data structures: Advice needed for creating the model structure Post by: Joel Hooks on March 01, 2009, 05:29:01 "There is a utility called PGProxyReservation listed in the 'Public Apps, Demos and Utilities' area of these forums that I believe is geared to this sort of scenario. You might want to scope that out before implementing."
This utility works really well after a few tweaks to handle dynamically named proxies. http://forums.puremvc.org/index.php?topic=830.0 I've used it in production on multiple projects. Title: Re: Composite data structures: Advice needed for creating the model structure Post by: olist on March 03, 2009, 03:55:28 Thanks to Cliff and Joel for the advice. After wracking my head during the weekend I decided to go for the one-proxy solution and did some refactoring. So now I'm glad to see that you would do it the same way.
Cheers, Oliver |