Everything Totally Explained


Ask & we'll explain, totally!
Object composition
Totally Explained


  NEW! All the latest news in the worlds of computer gaming, entertainment, the environment,  
finance, health, politics, science, stocks & shares, technology and much, much, more.  


View this entry using RSS

Everything about Struct totally explained

In computer science, object composition (not to be confused with function composition) is a way and practice 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. Composition is 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. Composition doesn't form a subtype but a new type.
   A real-world example of composition may be seen in an automobile: the objects wheel, steering wheel, seat, gearbox and engine may have no functionality by themselves, but if you compose them, they may form an automobile object, which has a higher function, greater than the sum of its parts in a trite sense.
   Composited (composed) objects are called fields, items, members or attributes, and the resulting composition a structure, storage record, tuple, user-defined type (UDT), or composite type. The terms usually vary across languages. Fields are given a unique name so that each one can be distinguished from the others. Sometimes an issue of ownership arises: when a composition is destroyed, should objects belonging to it be destroyed as well? If not, the case is sometimes called aggregation. For more, see the aggregation section below.

UML Notation

In UML, composition is depicted as a filled diamond and a solid line. It always implies a multiplicity of 1 or 0..1, as no more than one object at a time can have lifetime responsibility for another object.
   The more general form, aggregation, is depicted as an unfilled diamond and a solid line. The image below shows both composition and aggregation. The code below shows what the source code is likely to look like. // Composition class Car ; In aggregation, the object may only contain a reference or pointer to the object (and not have lifetime responsibility for it):
Sometimes aggregation is referred to as composition when the distinction between ordinary composition and aggregation is unimportant.
   The above code would transform into the following UML Class diagram:

Containment

Composition that's used to store several instances of the composited data type is referred to as containment. Examples of such containers are arrays, linked lists, binary trees and associative arrays.
   In UML, containment is depicted with a multiplicity of 1 or 0..n (depending on the issue of ownership), indicating that the data type is composed of an unknown amount of instances of the composited data type.

Aggregation in COM

In Microsoft's Component Object Model aggregation means that an object exports, as if it were their owner, one or several interfaces of another object it owns. Formally, this is more similar to composition or encapsulation than aggregation. However, instead of implementing the exported interfaces by calling the interfaces of the owned object, the interfaces of the owned object themselves are exported. The owned object is responsible for assuring that methods of those interfaces inherited from IUnknown actually invoke the corresponding methods of the owner. This is to guarantee that the reference count of the owner is correct and all interfaces of the owner are accessible through the exported interface, while no other (private) interfaces of the owned object are accessible.

Further Information

Get more info on 'Struct'.


External Link Exchanges

Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

    <a href="http://object_composition.totallyexplained.com">Object composition Totally Explained</a>

Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
   As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
This article contains text from the Wikipedia article Object composition (History) and is released under the GFDL | RSS Version