Flex 2 and ColdFusion: Are VO's always the way to go?
Posted by Joe Rinehart at 7:32 AM
15 comments - Categories:
Flex and ColdFusion
I'm working on an in-house Flex application right now, and I'm hitting a point where I'm concerned about the load associated with creating large collections of Value Objects. Background:
When dealing in Flex, it's a good idea to deal in typed transfer objects between the Flex client and the Java/CF backend. By "typed transfer objects," I mean something like a Value Object instead of simply a structure or associative array.
My problem:
I've got this list of, say, recipes. When displayed as a list, I just need to show the recipe's name and author. Each user can create "variations" on a recipe, and the recipe object has a "variations" property that contains an ordered array of variants on that recipe.
The thing is, I only need to deal with Variants when dealing with the details of a recipe: when they're shown as a list, or search results, all I care about is the name of the recipe and maybe its author's name.
However, when they're shown as detail, I want to show a list of all of a given recipe's variants.
It's easy to do SQL to return everything at once:
r.recipeId,
r.title,
v.title AS variantTitle
v.recipeId as variantId
FROM
recipe r
LEFT OUTER JOIN recipe v ON r.recipeId = v.originalRecipeId
However, my service facade then has to marshall many more VOs than is necessary for the list. Granted, I can cheat by creating a cache of VO's keyed by ID and cut down on the number created, but I'm still going to find situations where CF is going to want to create thousands of VOs in one request, and creating CFC's en masse just isn't CF's strong suit. FDS isn't an option here.
So, I'm stuck at this point where I almost want to return just a query, which comes across as an array of untyped Objects. Then, when someone views the details of a recipe, I'll go back to the server and load it.
Conclusion
I'm not too sure where I'll end up with this. I'm not a big fan of overoptimizing up-front: I'll probably just go the "swarm of VOs" route, and if it never causes a problem, I'll leave well enough alone.
Owen van Dijk wrote on 12/04/06 8:27 AM
We have a deep, nested object model with multiple VO's containing collections of one or more VO's. What we did is to check which information we absolutely needed 'on first load' (say getItems() and when we needed more information, we created a service ( say getCommentsByItemId(id) ) that returns an collection of CommentVO's for that ItemVO. In the result handler of that service i then 'fill' the empty VO with more data.