Compositions are based on the principle that everything that is, only exists through or because of relations with other things.
A composition exists only because it relates to other compositions and/or unit(s).
Compositions use some aspects of Object Oriented (OO) software principles but it also diverges in many ways from it.
It has however nothing to do with a class. A class is the static definition of an object (state and behavior) and includes constructors (which can be implicit) to instantiate an object from it.
Compositions have no static information whatsoever. In OO terminology we could say that compositions are instantiated objects.
For C programmers: think of a Composition as an instantiated struct of void
pointers
For Java programmers: think of a Composition as a container object (e.g. a Vector)
For XML programmers: think of a Composition as an element
The variables in objects are the relations to other objects. In UML terminology objects have either associations, aggregations or compositions with other objects. The difference between these 3 terms is only relevant in OO, therefore we will only use the term relation.
A class defines behavior which is bound to the object instantiated through that class.
This 'encapsulation' of behavior is too restrictive and rigid.
Encapsulation of behavior has the following consequences
The OO world is wrestling with this problem and they invented a cumbersome patch called Multi-Methods.
Inheritance is a very rigid mechanism applied to a class (and not to an object) which delegates all behavior and relations not overridden in the base class to a super class.
It is extremely rigid because ALL behavior and ALL relations are delegated to the super class. One of the results is the infamous 'fragile base class' syndrome.
Note:
If you are starting an OO project then my advice is to abandon the ALL or NOTHING delegation that inheritance imposes with a selective delegation model (and preferably based on interfaces for the behavior).
Koen Van Exem is currently writing a book on "Compositions" and he hopes to have a draft finished in the near future.
If you would like to apply the theory of Compositions right now, the technology that comes closest to Compositions is XML in combination with DTD and XSLT.