In computer science, object composition (not to be confused with function composition) is a way to combine simple objects or data types into more complex ones. Compositions are a critical building block of many basic data structures, including the tagged union, the linked list, and the binary tree, as well as the object used in object-oriented programming.
A real-world example of composition may be seen in the relation of an automobile to its parts, specifically: the automobile 'has or is composed from' objects including steering wheel, seat, gearbox and engine.
When, in a language, objects are typed, types can often be divided into composite and noncomposite types, and composition can be regarded as a relationship between types: an object of a composite type (e.g. car) "has an" object of a simpler type (e.g. wheel).
Composition must be distinguished from subtyping, which is the process of adding detail to a general data type to create a more specific data type. For instance, cars may be a specific type of vehicle: car is a vehicle. Subtyping doesn't describe a relationship between different objects, but instead, says that objects of a type are simultaneously objects of another type.
In programming languages, composite objects are usually expressed by means of references from one object to another; depending on the language, such references may be known as fields, members, properties or attributes, and the resulting composition as a structure, storage record, tuple, user-defined type (UDT), or composite type. Fields are given a unique name so that each one can be distinguished from the others. However, having such references doesn't necessarily mean that an object is a composite. It is only called composite if the objects it refers to are really its parts, i.e. have no independent existence. For details, see the aggregation section below.
Read more about Object Composition: UML Notation, Composite Types in C, Recursive Composition, Timeline of Composition in Various Languages, Aggregation, Containment, Aggregation in COM
Famous quotes containing the words object and/or composition:
“Did men but consider that the sun, moon, and stars, and every other object of the senses, are only so many sensations in their minds, which have no other existence but barely being perceived, doubtless they would never fall down and worship their own ideas; but rather address their homage to that eternal invisible Mind which produces and sustains all things.”
—George Berkeley (16851753)
“There is singularly nothing that makes a difference a difference in beginning and in the middle and in ending except that each generation has something different at which they are all looking. By this I mean so simply that anybody knows it that composition is the difference which makes each and all of them then different from other generations and this is what makes everything different otherwise they are all alike and everybody knows it because everybody says it.”
—Gertrude Stein (18741946)