Thursday, April 20, 2006

Composite Objects

Another OO lesson:

When working with complex objects, try to view them in groups of behavior. Don't view it as one gigantic object, split it into behaviorial groups. You can then take advantage of so called 'lazy' or 'late' instantiation. For example, you might have an "Insurance Policy" object. You don't want to retrieve and build the entire object every time. That would cause poor performance and memory overhead.
Instead have a minimum set of properties that are always retrieved and then group the remaining into separate objects. For example, coverages, underwriters, auditors, etc. You can then break those subgroups into smaller late instantiated objects as well.

A little extra though now will save you a great deal of performance pain later!


Post a Comment

<< Home