O'Reilly logo

Object-Oriented Programming in ColdFusion by Matt Gifford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Aggregation

In comparison to composition in which an object can only exist if all of its composite parts also exist, the concept of aggregation is not as strict. Instead, an aggregated object can reference other objects, but it does not need them to exist.

We can see a simple example of aggregation in action if we again reference our Car object. Unlike composition, where our car needed an engine to exist (after all, what is a car without an engine), a car can have a driver, but it does not need the driver to exist.

Let's revise our current Car.cfc component to handle the possibility of managing a Driver object.

<cfcomponent displayname="Car"
output="false"
hint="I am the Car Class.">
<cfproperty name="engine" type="any" default="" /> <cfproperty ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required