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)

    He’s one of those know-it-all types that, if you flatter the wig off him, he chatter like a goony bird at mating time.
    —Michael Blankfort. Lewis Milestone. Johnson (Reginald Gardner)