Dog Breeds Information and More
  Komondor - Dog Breeds Facts and Information Dog Breeds Selector A to Z dog breeds Forums

 
Dog names
Dog training
Toy dogs
Intelligence
Dog health
Dog worship
Ticks

 
Golden Retriever
Labrador Retriever
Jack Russell
 
Find a Breed
 
Dog Breeds Encyclopedia
 

Composition (computer science)

(Redirected from Composite type)

In computer science, composition is a way to combine simple data types into more complex data types. It should be contrasted with subtyping, which is the process of adding detail to a general data type to create a more specific data type.

In composition, the composite type "has an" object of a simpler type, while in subtyping, the subtype "is an" instance of its parent type.

The simpler types from which a composite type is constructed can be primitive types, or they can be other composite types which are expanded recursively.

Composite types typically have one simpler type to represent each attribute of an object. Attributes are usually given some name to allow accessing them.

Aggregation is a special type of composition in which the composite type is responsible for the lifetimes of the contained objects.

In UML, aggregation is depicted as a filled diamond. It always implies a multiplicity of 1, as only one object at a time can have lifetime responsibility for another object. The more general composition is depicted as an un-filled diamond.

Example

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 Object, and it could inherit some attributes from Object (every object has an age), while extending the definition of Object with new attributes (not every object has a sex, but every person does).

See also

The contents of this article are licensed from Wikipedia.org under the
GNU Free Documentation License. How to see transparent copy