Komposition (EN)

Concept

Strong relationship between classes where the dependent element cannot exist without the main element

Composition in Object Orientation

classDiagram   class Ganzes {     +attribut1     +methode1()   }   class Teil {     +attribut2     +methode2()   }   Ganzes "1" *-- "0..n" Teil : enthält 

Characteristics

  • Strong Existence Dependency: Part cannot exist without Whole
  • Lifecycle Coupling: Part is created and destroyed with Whole
  • Transitivity: If A composes B and B composes C, then A indirectly composes C

Example

  • A car (Whole) has an engine (Part) - without car, engine cannot exist
  • A webpage (Whole) has multiple images (Parts) - images are useless without webpage
Quelle: AI Generated