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 childrens self-confidence so they dare to take risks. It is an environment that nurtures a love of learning.”
—Carol B. Hillman (20th century)
“If there is nothing new on the earth, still the traveler always has a resource in the skies. They are constantly turning a new page to view. The wind sets the types on this blue ground, and the inquiring may always read a new truth there.”
—Henry David Thoreau (18171862)