OOPortal OOPortal


User Defined Types  «Prev 

Class Composition

Sometimes an object is made up of other objects.
For example, an airplane is made up of a fuselage, wings, engines, landing gear, flaps, and so on.

Class Composition

  1. Caption: As you may remember from high school geometry, a line is defined by two points. Thus, the Line class might have two Point attributes (each one an instance of the Point class).
  2. Caption: Composition is when one class contains another class as an attribute. Composition is indicated in a class diagram by connecting the owning class to the owned class with a line.
  3. Caption: Generally, the type and direction of the relationship are indicated by a few words such as "has a," "owns a," "uses a," or "refers to," followed by an arrowhead indicating the direction of the relationship.
  4. Caption: This picture shows only a single point, when in fact a Line object contains two Point objects. This is indicated by adding the numeral 2 above the line and next to the point.

As you may remember from high school geometry, a line is defined by two points. Thus the Line class might have two Point attributes.
As you may remember from high school geometry, a line is defined by two points. Thus the Line class might have two Point attributes.

Composition is when one class contains another class as an attribute. Composition is indicated in a class diagram by connecting the owning class to the owned class with a line.
Composition is when one class contains another class as an attribute. Composition is indicated in a class diagram by connecting the owning class to the owned class with a line.

The type and direction of the relationship is indicated by a few words such as (has a), (owns a) , or (refers to) followed by an arrowhead indicating the direction of the relationship.
The type and direction of the relationship is indicated by a few words such as (has a), (owns a) , or (refers to) followed by an arrowhead indicating the direction of the relationship.

This picture only shows a single point, when in fact a Line object contains two Point objects. This is indicated by adding the numeral 2 above the line and next to the point.
This picture only shows a single point, when in fact a Line object contains two Point objects. This is indicated by adding the numeral 2 above the line and next to the point.