I am really liking PureMVC a lot. It is clean, well thought-out and very flexible.
As I learn it, I still have some doubts about the role of Value Objects in its architecture. For instance, there is a post (http://forums.puremvc.org/index.php?topic=243.0
) where Cliff says:
Value Objects should be just that, carriers for data. Proxies should generally have the methods that massage that data, translate it or simply expose it to the app.
The main reason for only having attributes on a value object is that it is intended for shuttling data across tiers of an application.
That includes across client and server tiers. When marshaling and unmarshaling an object into a transfer format like XML, you can only send values. The methods wont go, or necessarily even make sense on the other side.
OK... First of all, in the Employees example, the UserVO is not a pure Value Object in this sense. It has two methods: isValid() and givenName(). So it is more like a Domain Object, which seems to be benefic to the application.
Next, the quote describes a Value Object as a Data Transfer Object that should only contain data, not any behavior, and that will be shuttled between application layers, including between client and server.
Now, it seems I can easily use an anonymous object as a DTO between the client and the server. It also seems that the client application should not be too tied to the way the server represents the data. I would consider the DTO as a kind of calling protocol to the service, that could possibly require conversion to data types more adequate for a client application. Again, it seems odd that a view component would receive the same DTO that would be returned by a remote service.
Let me try to clarify my thoughts with an example.
A "Project" entity could have a "Manager" attribute. That could be represented by an integer key on the service. But on the client I would like it to be an instance of a Manager class, not just an integer. Or at least to have also the manager name, that I would retrieve from another proxy, so it would be easier to sort on grids by the manager's name.
I also could want my project objects to have a collection of milestones. In the service that would be represented by another DTO for the Milestone entity, that would probably have the integer ID of the project and a milestone name and due date. But I would like my client-side project object to have a collection of milestones.
I also could want to go full domain object on this, and have the client-side behavior associated to the project on the project object itself, like the sample does with the User object.
I've read the best practices document three times, read all the other documents I could find on this site, downloaded and browsed the examples, created my own sample application (http://fernandoacorreia.wordpress.com/2008/07/30/flex-client-using-puremvc/
), read all articles I could find in blogs about PureMVC, but it is still not very clear to me how we can deal in PureMVC with a database-based scenario like I described (Managers <-> Projects <-> Milestones) and how we can have a client-side abstraction of this objects that is not too restricted by the service interface.
Actually I am not certain if this strategy of using a VO and putting the instance behavior on the proxy is a definite best practice on PureMVC or if it is just a convenience. That is, would I run into trouble if I decided to use anonymous objects as DTOs to the server, use domain objects with attributes and instance methods within the client and kept in the proxy only the methods common in the Repository pattern, like CRUD methods?
The only possible complication I can think of is that the view components would be able to call the methods on the domain objects and that could break the isolation. Then again, that's exactly what the Employees example does with the isValid() and givenName() methods of the User "Domain" object...
Any help will be appreciated.