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 bourgeoisie loves so-called positive types and novels with happy endings since they lull one into thinking that it is fine to simultaneously acquire capital and maintain ones innocence, to be a beast and still be happy.”
—Anton Pavlovich Chekhov (18601904)