Skip to main content

Composition And Encapsulation

Car

Demonstrates composition and encapsulation.

  • Composition: Car must have CarInfo (shown with filled diamond *--)
  • Association: Car may have OwnerInfo (shown with arrow -->) - zero or one owner
  • Multiple constructors showing different initialization options
  • Private properties have getters and setters
  • Comparison methods to compare cars

CarInfo

Essential information about a car (composition relationship).

  • Cannot exist without a Car
  • Private properties have getters and setters

OwnerInfo

Information about the car's owner (association relationship).

  • Can exist independently of Car
  • Private properties have getters and setters

Parking

Manages multiple cars (one-to-many association).

  • Methods to count cars and search by brand
  • Private properties have getters and setters