RIAs, Adobe Flex, and related topics

About
Resume
Contact

October 18, 2007

Managed associations vs. hierarchical values

Filed under: Flex, OOAD — jimrobson @ 5:39 pm

I promised to post a follow-up to my comments on Jeff Vroom’s presentation at MAX, so let me get to it before too much time passes.

There are different ways of representing the properties of complex objects. For example, let’s consider the pickup truck class. Every pickup has a cab (where the people sit) and the bed (where the people put their stuff). There are certain properties of the pickup that are really specific to the cab (for example, the number of people it can seat, and whether or not the rear window slides). Likewise, there are properties that are specific to the bed (fleetside or stepside, number of tie-downs, etc.). We could represent the pickup truck such that the class includes all of these properties in a hierarchy.

complex type as monolithic hierarchy

Another way to represent the pickup truck is to use discrete classes for the bed and the cab. In this way, we can encapsulate the cab’s properties and functionality in the Cab class, and the bed’s in the Bed class. We then associate each instance of the PickupTruck class with an instance of the Cab class and an instance of the Bed class. This results in a more flexible, extensible, and maintainable design.

managed associations

When using LiveCycle Data Services (LCDS), there are specific advantages to using these managed associations rather than lumping everything together into hierarchical values. If we put all of the components together into a single hierarchical class, then LCDS treats it as a blob, so that the entire class instance is updated every time a change is made to any property. For example, if we change the value of cab.isAirConditioned from false to true, then all of the tables that provide data for our PickupTruck class are updated. However, if we use managed associations and change the value Cab.isAirConditioned, then only the table that provides Cab data gets updated, so it is less resource-intensive.

Using managed associations with LCDS also provides advantages for lazy loading. On application startup we could load all of the data for our PickupTruck objects but just load the IDs of the Cabs and Beds. Then we would pull the detailed Cab and Bed data as needed.

In short, Jeff affirmed that managed associations are preferred as long as IDs are available for the referenced objects. If the Cab and Bed tables don’t have IDs, then you may need to pile everything into the Pickup class. Otherwise, it’s better to write separate classes.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment


Powered by WordPress