The Full Wiki



More info on Composition (computer science)

Composition (computer science): Wikis


Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.
In computer science, composition is a way to combine objects where a structure might contain data objects, namely

:the "structure has a object that is a member of some class",

rather than the alternative

:"structure is an instance of some class".

In the Unified Modeling Language has-a 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. When implementing in a language with garbage collection the object can be used and created without worrying about memory leaks.

In the example below, C has no garbage collection, so the object must be freed by hand after the object has passed its useful life.

Example



This is an example of composition in C.
<pre>
struct Person {
int age;
char name[16];
};
</pre>

See also

  • Aggregation -- Composite pattern -- Law of Demeter --


  • ---------------
    The following is to be merge.

    In computer science, a composite type, the opposite to a primitive type, is a datatype made up of more primitive types. The type is the most foundmental type besides primitive, supported by the vast majority of programming languages and is used heavily.

    The type is typically used to form a type of value representing attributes of particular object. Attributes are mostly given some name to allow accessing to it. It is common to combine composite types to make a new composite type.

    Values with a composite type are stored in the memory in such a way that each attribute is followed by another attribute. If the type consists of other composite types, such composite type is expanded recursively. An alignment of each is often on issue because

    Example



    This is a composite type of struct in C.

    <pre>
    struct Person {
    int age;
    enum { male, female };
    };
    </pre>









    Got something to say? Make a comment.
    Your name
    Your email address
    Message
    Please enter the solution to case below
    70+12=