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)
“The wider the range of possibilities we offer children, the more intense will be their motivations and the richer their experiences. We must widen the range of topics and goals, the types of situations we offer and their degree of structure, the kinds and combinations of resources and materials, and the possible interactions with things, peers, and adults.”
—Loris Malaguzzi (19201994)