Application and Domain Models: Examples of Aggregate and Composite Design

2007 June 05
tags: Ideas · Modeling · UML
by Paul Marcotte
I've been using UML more often to visualize object relationships, so after reading Brian Rinaldi's recent posts on ColdSpring, Objects and Composition, I researched object composition and learned the subtle difference between Composition and Aggregation.When an object that is part of a composite will continue to exist after the composite is discarded (a.k.a Singleton), a pointer to the object is used, because the aggregate object cannot be discared. For an object to be truly composite, it must be completely disposable. That is it must be composed of transient objects. Don't ask what to call objects that both aggregate a Singleton and compose a Transient (a Transient User object might aggregate a Singleton UserDAO and Transient UserValidator). The following UML diagrams of Brian's domain models illustrate the difference between aggregate and composite objects. The first diagram is the domain model for Brian's xbox console from part one of his series. The lines ending in a filled diamond indicate that the console is a composite of up to 4 controls (0..4), but unlimited accessories and games (0..*). In Brian's xbox application, a console is a transient object that will exist only for the life of a request. The ColdSpring example in Part 2 of Brian's series defines a consoleService that is an aggregate of its own DAO and Gateway and the DAO and Gateway of control, game and accessory as well. These Singleton objects are illustrated in the diagram below. Making the distinction between Singletons and Transients, helped me to understand Aggregation and Composition, and application and domain models. Although not a hard a fast rule, one might suggest that an application model represents aggregate singletons, while a domain model represents composite transients.