<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
object	B-Language
composition	I-Language
and	O
object	B-Language
aggregation	I-Language
are	O
closely	O
related	O
ways	O
to	O
combine	O
objects	O
or	O
data	O
types	O
into	O
more	O
complex	O
ones	O
.	O
</s>
<s>
In	O
conversation	O
the	O
distinction	O
between	O
composition	B-Language
and	O
aggregation	O
is	O
often	O
ignored	O
.	O
</s>
<s>
Common	O
kinds	O
of	O
compositions	O
are	O
objects	O
used	O
in	O
object-oriented	B-Language
programming	I-Language
,	O
tagged	B-Language
unions	I-Language
,	O
sets	O
,	O
sequences	O
,	O
and	O
various	O
graph	B-Application
structures	O
.	O
</s>
<s>
Object	B-Language
compositions	I-Language
relate	O
to	O
,	O
but	O
are	O
not	O
the	O
same	O
as	O
,	O
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
Object	B-Language
composition	I-Language
refers	O
to	O
the	O
logical	O
or	O
conceptual	O
structure	O
of	O
the	O
information	O
,	O
not	O
the	O
implementation	O
or	O
physical	O
data	B-General_Concept
structure	I-General_Concept
used	O
to	O
represent	O
it	O
.	O
</s>
<s>
Data	B-General_Concept
structures	I-General_Concept
such	O
as	O
arrays	B-Data_Structure
,	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
hash	B-Algorithm
tables	I-Algorithm
,	O
and	O
many	O
others	O
can	O
be	O
used	O
to	O
implement	O
either	O
of	O
them	O
.	O
</s>
<s>
Perhaps	O
confusingly	O
,	O
some	O
of	O
the	O
same	O
terms	O
are	O
used	O
for	O
both	O
data	B-General_Concept
structures	I-General_Concept
and	O
composites	O
.	O
</s>
<s>
For	O
example	O
,	O
"	O
binary	O
tree	B-Application
"	O
can	O
refer	O
to	O
either	O
:	O
as	O
a	O
data	B-General_Concept
structure	I-General_Concept
it	O
is	O
a	O
means	O
of	O
accessing	O
a	O
linear	O
sequence	O
of	O
items	O
,	O
and	O
the	O
actual	O
positions	O
of	O
items	O
in	O
the	O
tree	B-Application
are	O
irrelevant	O
(	O
the	O
tree	B-Application
can	O
be	O
internally	O
rearranged	O
however	O
one	O
likes	O
,	O
without	O
changing	O
its	O
meaning	O
)	O
.	O
</s>
<s>
However	O
,	O
as	O
an	O
object	B-Language
composition	I-Language
,	O
the	O
positions	O
are	O
relevant	O
,	O
and	O
changing	O
them	O
would	O
change	O
the	O
meaning	O
(	O
as	O
for	O
example	O
in	O
cladograms	B-Application
)	O
.	O
</s>
<s>
Object-oriented	B-Language
programming	I-Language
is	O
based	O
on	O
objects	O
to	O
encapsulate	B-Application
data	O
and	O
behavior	O
.	O
</s>
<s>
It	O
uses	O
two	O
main	O
techniques	O
for	O
assembling	O
and	O
composing	O
functionality	O
into	O
more	O
complex	O
ones	O
,	O
sub-typing	O
and	O
object	B-Language
composition	I-Language
.	O
</s>
<s>
Object	B-Language
composition	I-Language
is	O
about	O
combining	O
objects	O
within	O
compound	O
objects	O
,	O
and	O
at	O
the	O
same	O
time	O
,	O
ensuring	O
the	O
encapsulation	B-Application
of	O
each	O
object	O
by	O
using	O
their	O
well-defined	O
interface	B-Application
without	O
visibility	O
of	O
their	O
internals	O
.	O
</s>
<s>
In	O
this	O
regard	O
,	O
object	B-Language
composition	I-Language
differs	O
from	O
data	B-General_Concept
structures	I-General_Concept
,	O
which	O
do	O
not	O
enforce	O
encapsulation	B-Application
.	O
</s>
<s>
Object	B-Language
composition	I-Language
may	O
also	O
be	O
about	O
a	O
group	O
of	O
multiple	O
related	O
objects	O
,	O
such	O
as	O
a	O
set	O
or	O
a	O
sequence	O
of	O
objects	O
.	O
</s>
<s>
Delegation	B-Application
may	O
enrich	O
composition	B-Language
by	O
forwarding	O
requests	O
or	O
calls	O
made	O
to	O
the	O
enclosing	O
composite	O
object	O
to	O
one	O
of	O
its	O
internal	O
components	O
.	O
</s>
<s>
In	O
class-based	O
and	O
typed	O
programming	O
languages	O
,	O
types	O
can	O
be	O
divided	O
into	O
composite	O
and	O
non-composite	O
types	O
,	O
and	O
composition	B-Language
can	O
be	O
regarded	O
as	O
a	O
relationship	O
between	O
types	O
:	O
an	O
object	O
of	O
a	O
composite	O
type	O
(	O
e.g.	O
</s>
<s>
car	O
)	O
"	O
has	B-Application
"	O
objects	O
of	O
other	O
types	O
(	O
e.g.	O
</s>
<s>
Composition	B-Language
must	O
be	O
distinguished	O
from	O
subtyping	O
,	O
which	O
is	O
the	O
process	O
of	O
adding	O
detail	O
to	O
a	O
general	O
data	O
type	O
to	O
create	O
a	O
more	O
specific	O
data	O
type	O
.	O
</s>
<s>
The	O
study	O
of	O
such	O
relationships	O
is	O
ontology	B-Language
.	O
</s>
<s>
In	O
prototype-based	B-Application
programming	I-Application
languages	I-Application
such	O
as	O
JavaScript	B-Language
,	O
objects	O
can	O
dynamically	O
inherit	O
the	O
behaviors	O
from	O
a	O
prototype	B-Application
object	O
at	O
the	O
moment	O
of	O
their	O
instantiation	O
.	O
</s>
<s>
Composition	B-Language
must	O
be	O
distinguished	O
from	O
prototyping	O
:	O
the	O
newly	O
instantiated	O
object	O
inherits	O
the	O
composition	B-Language
of	O
its	O
prototype	B-Application
,	O
but	O
it	O
may	O
itself	O
be	O
composed	O
on	O
its	O
own	O
.	O
</s>
<s>
The	O
items	O
within	O
a	O
composite	O
object	O
may	O
be	O
referred	O
to	O
as	O
attributes	O
,	O
fields	B-Application
,	O
members	O
,	O
properties	O
,	O
or	O
other	O
names	O
,	O
and	O
the	O
resulting	O
composition	B-Language
as	O
composite	O
type	O
,	O
storage	B-General_Concept
record	I-General_Concept
,	O
structure	O
,	O
tuple	B-Application
,	O
or	O
a	O
user-defined	B-Language
type	I-Language
(	O
UDT	O
)	O
.	O
</s>
<s>
In	O
UML	B-Language
modeling	O
,	O
objects	O
can	O
be	O
conceptually	O
composed	O
,	O
independently	O
of	O
the	O
implementation	O
with	O
a	O
programming	O
language	O
.	O
</s>
<s>
There	O
are	O
four	O
ways	O
of	O
composing	O
objects	O
in	O
UML	B-Language
:	O
property	O
,	O
association	O
,	O
aggregation	O
and	O
composition	B-Language
:	O
</s>
<s>
A	O
composition	B-Language
,	O
also	O
called	O
a	O
composite	O
aggregation	O
,	O
is	O
a	O
kind	O
of	O
aggregation	O
that	O
models	O
a	O
part/whole	O
relationship	O
between	O
a	O
composite	O
(	O
whole	O
)	O
and	O
a	O
group	O
of	O
exclusively	O
owned	O
parts	O
.	O
</s>
<s>
The	O
relationship	O
between	O
the	O
aggregate	O
and	O
its	O
components	O
is	O
a	O
weak	O
"	O
has-a	B-Application
"	O
relationship	O
:	O
The	O
components	O
may	O
be	O
part	O
of	O
several	O
aggregates	O
,	O
may	O
be	O
accessed	O
through	O
other	O
objects	O
without	O
going	O
through	O
the	O
aggregate	O
,	O
and	O
may	O
outlive	O
the	O
aggregate	O
object	O
.	O
</s>
<s>
The	O
relationship	O
between	O
the	O
composite	O
and	O
its	O
parts	O
is	O
a	O
strong	O
“	O
has-a	B-Application
”	O
relationship	O
:	O
The	O
composite	O
object	O
has	B-Application
sole	O
"	O
responsibility	O
for	O
the	O
existence	O
and	O
storage	O
of	O
the	O
composed	O
objects	O
"	O
,	O
the	O
composed	O
object	O
can	O
be	O
part	O
of	O
at	O
most	O
one	O
composite	O
,	O
and	O
"	O
If	O
a	O
composite	O
object	O
is	O
deleted	O
,	O
all	O
of	O
its	O
part	O
instances	O
that	O
are	O
objects	O
are	O
deleted	O
with	O
it	O
"	O
.	O
</s>
<s>
Thus	O
in	O
UML	B-Language
,	O
composition	B-Language
has	B-Application
a	O
more	O
narrow	O
meaning	O
than	O
the	O
usual	O
object	B-Language
composition	I-Language
.	O
</s>
<s>
the	O
composition	B-Language
as	O
a	O
filled	O
diamond	O
on	O
the	O
side	O
of	O
the	O
composite	O
and	O
a	O
solid	O
line	O
.	O
</s>
<s>
Aggregation	O
differs	O
from	O
ordinary	O
composition	B-Language
in	O
that	O
it	O
does	O
not	O
imply	O
ownership	O
.	O
</s>
<s>
In	O
composition	B-Language
,	O
when	O
the	O
owning	O
object	O
is	O
destroyed	O
,	O
so	O
are	O
the	O
contained	O
objects	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
university	O
owns	O
various	O
departments	O
(	O
e.g.	O
,	O
chemistry	O
)	O
,	O
and	O
each	O
department	O
has	B-Application
a	O
number	O
of	O
professors	O
.	O
</s>
<s>
Therefore	O
,	O
a	O
university	O
can	O
be	O
seen	O
as	O
a	O
composition	B-Language
of	O
departments	O
,	O
whereas	O
departments	O
have	O
an	O
aggregation	O
of	O
professors	O
.	O
</s>
<s>
Composition	B-Language
is	O
usually	O
implemented	O
such	O
that	O
an	O
object	O
contains	O
another	O
object	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
C++	B-Language
:	O
</s>
<s>
Sometimes	O
aggregation	O
is	O
referred	O
to	O
as	O
composition	B-Language
when	O
the	O
distinction	O
between	O
ordinary	O
composition	B-Language
and	O
aggregation	O
is	O
unimportant	O
.	O
</s>
<s>
The	O
above	O
code	O
would	O
transform	O
into	O
the	O
following	O
UML	B-Language
Class	O
diagram	O
:	O
</s>
<s>
In	O
Microsoft	O
's	O
Component	B-Application
Object	I-Application
Model	I-Application
,	O
aggregation	O
means	O
that	O
an	O
object	O
exports	O
,	O
as	O
if	O
it	O
were	O
their	O
owner	O
,	O
one	O
or	O
several	O
interfaces	B-Application
of	O
another	O
object	O
it	O
owns	O
.	O
</s>
<s>
Formally	O
,	O
this	O
is	O
more	O
similar	O
to	O
composition	B-Language
or	O
encapsulation	B-Application
than	O
aggregation	O
.	O
</s>
<s>
However	O
,	O
instead	O
of	O
implementing	O
the	O
exported	O
interfaces	B-Application
by	O
calling	O
the	O
interfaces	B-Application
of	O
the	O
owned	O
object	O
,	O
the	O
interfaces	B-Application
of	O
the	O
owned	O
object	O
themselves	O
are	O
exported	O
.	O
</s>
<s>
The	O
owned	O
object	O
is	O
responsible	O
for	O
assuring	O
that	O
methods	O
of	O
those	O
interfaces	B-Application
inherited	O
from	O
actually	O
invoke	O
the	O
corresponding	O
methods	O
of	O
the	O
owner	O
.	O
</s>
<s>
This	O
is	O
to	O
guarantee	O
that	O
the	O
reference	O
count	O
of	O
the	O
owner	O
is	O
correct	O
and	O
all	O
interfaces	B-Application
of	O
the	O
owner	O
are	O
accessible	O
through	O
the	O
exported	O
interface	B-Application
,	O
while	O
no	O
other	O
(	O
private	O
)	O
interfaces	B-Application
of	O
the	O
owned	O
object	O
are	O
accessible	O
.	O
</s>
<s>
Composition	B-Language
that	O
is	O
used	O
to	O
store	O
several	O
instances	O
of	O
the	O
composited	O
data	O
type	O
is	O
referred	O
to	O
as	O
containment	O
.	O
</s>
<s>
Examples	O
of	O
such	O
containers	O
are	O
arrays	B-Data_Structure
,	O
associative	B-Application
arrays	I-Application
,	O
binary	O
trees	O
,	O
and	O
linked	B-Data_Structure
lists	I-Data_Structure
.	O
</s>
<s>
In	O
UML	B-Language
,	O
containment	O
is	O
depicted	O
with	O
a	O
multiplicity	O
of	O
0	O
..	O
or	O
1	O
..	O
,	O
indicating	O
that	O
the	O
composite	O
object	O
is	O
composed	O
of	O
an	O
unknown	O
number	O
of	O
instances	O
of	O
the	O
composed	O
class	O
.	O
</s>
<s>
Each	O
node	O
in	O
a	O
tree	B-Application
may	O
be	O
a	O
branch	O
or	O
leaf	O
;	O
in	O
other	O
words	O
,	O
each	O
node	O
is	O
a	O
tree	B-Application
at	O
the	O
same	O
time	O
when	O
it	O
belongs	O
to	O
another	O
tree	B-Application
.	O
</s>
<s>
In	O
UML	B-Language
,	O
recursive	O
composition	B-Language
is	O
depicted	O
with	O
an	O
association	O
,	O
aggregation	O
or	O
composition	B-Language
of	O
a	O
class	O
with	O
itself	O
.	O
</s>
<s>
The	O
composite	O
design	O
pattern	O
is	O
an	O
object	B-Language
oriented	I-Language
design	O
based	O
on	O
composite	O
types	O
,	O
that	O
combines	O
recursive	O
composition	B-Language
and	O
containment	O
to	O
implement	O
complex	O
part-whole	O
hierarchies	O
.	O
</s>
<s>
This	O
is	O
an	O
example	O
of	O
composition	B-Language
in	O
C	B-Language
.	O
</s>
<s>
Each	O
structure	O
then	O
"	O
has	B-Application
an	O
"	O
age	O
,	O
name	O
,	O
and	O
an	O
employment	O
type	O
.	O
</s>
<s>
C	B-Language
calls	O
a	O
record	O
a	O
struct	B-Application
or	O
structure	O
;	O
object-oriented	B-Language
languages	I-Language
such	O
as	O
Java	B-Language
,	O
Smalltalk	B-Application
,	O
and	O
C++	B-Language
often	O
keep	O
their	O
records	O
hidden	O
inside	O
objects	O
(	O
class	O
instances	O
)	O
;	O
languages	O
in	O
the	O
ML	B-Language
family	O
simply	O
call	O
them	O
records	O
.	O
</s>
<s>
COBOL	B-Application
was	O
the	O
first	O
widespread	O
programming	O
language	O
to	O
support	O
records	O
directly	O
;	O
ALGOL	B-Language
68	I-Language
got	O
it	O
from	O
COBOL	B-Application
and	O
Pascal	B-Application
got	O
it	O
,	O
more	O
or	O
less	O
indirectly	O
,	O
from	O
ALGOL	B-Language
68	I-Language
.	O
</s>
<s>
Common	B-Language
Lisp	I-Language
provides	O
structures	O
and	O
classes	O
(	O
the	O
latter	O
via	O
the	O
Common	B-Application
Lisp	I-Application
Object	I-Application
System	I-Application
)	O
.	O
</s>
<s>
Arrays	B-Data_Structure
were	O
the	O
only	O
composite	O
data	O
type	O
in	O
Algol	B-Language
60	I-Language
.	O
</s>
<s>
For	O
example	O
,	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
might	O
be	O
declared	O
as	O
:	O
</s>
<s>
For	O
ALGOL	B-Language
68	I-Language
only	O
the	O
type	O
name	O
appears	O
to	O
the	O
left	O
of	O
the	O
equality	O
,	O
and	O
most	O
notably	O
the	O
construction	O
is	O
made	O
–	O
and	O
can	O
be	O
read	O
–	O
from	O
left	O
to	O
right	O
without	O
regard	O
to	O
priorities	O
.	O
</s>
<s>
Fortran	O
77	O
has	B-Application
arrays	B-Data_Structure
,	O
but	O
lacked	O
any	O
formal	O
record/structure	O
definitions	O
.	O
</s>
<s>
Ada	O
95	O
brought	O
OOP	O
concepts	O
through	O
tagged	O
types	O
(	O
the	O
equivalent	O
of	O
a	O
C++	B-Application
class	I-Application
)	O
,	O
Ada	O
2012	O
added	O
support	O
for	O
substitution	B-Application
verification	O
through	O
class-wide	O
contracts	O
.	O
</s>
<s>
Common	B-Language
Lisp	I-Language
provides	O
structures	O
and	O
the	O
ANSI	B-Language
Common	I-Language
Lisp	I-Language
standard	I-Language
added	O
CLOS	B-Application
classes	O
.	O
</s>
<s>
For	O
more	O
details	O
about	O
composition	B-Language
in	O
C/C	O
++	O
,	O
see	O
Composite	O
type	O
.	O
</s>
