In computer science, composition is a way to combine objects where a structure might contain data objects, namely
- the "structure has a object that is a member of some class",
- "structure is a instance of some class".
In the example below, C has no garbage collection, so the object must be freed by hand after the object has passed its useful life.
This is an example of composition in C.
Example
struct Person {
int age;
char name[16];
};
See also