Object Composition - Composite Types in C

Composite Types in C

This is an example of composition in C.

typedef struct { int age; char *name; enum { male, female } sex; } Person;

In this example, the primitive types int, char *, and enum {male, female} are combined to form the composite type of Person. Each object of type Person then "has an" age, name, and sex.

If a Person type were instead created by subtyping, it might be a subtype of Organism, and it could inherit some attributes from Organism (every organism has an age), while extending the definition of Organism with new attributes (not every organism has a gender, but every person does).

Read more about this topic:  Object Composition

Famous quotes containing the words composite and/or types:

    A positive learning climate in a school for young children is a composite of many things. It is an attitude that respects children. It is a place where children receive guidance and encouragement from the responsible adults around them. It is an environment where children can experiment and try out new ideas without fear of failure. It is an atmosphere that builds children’s self-confidence so they dare to take risks. It is an environment that nurtures a love of learning.
    Carol B. Hillman (20th century)

    ... there are two types of happiness and I have chosen that of the murderers. For I am happy. There was a time when I thought I had reached the limit of distress. Beyond that limit, there is a sterile and magnificent happiness.
    Albert Camus (1913–1960)