Object relationships in software design — which construct implements a “Has a” relationship?

C# Programming Inheritance Difficulty: Easy
Choose an option
  • A
    Polymorphism
  • B
    Templates
  • C
    Containership (composition/aggregation)
  • D
    Encapsulation
  • E
    Inheritance

Answer

Correct Answer: Containership (composition/aggregation)

Explanation

Introduction / Context:In object-oriented design, relationships between entities are described using specific mechanisms. The “Has a” relationship means one object owns, contains, or aggregates another object.

Given Data / Assumptions:

  • We are mapping conceptual relationships to language-agnostic design constructs.
  • Terminology: containership includes composition and aggregation.

Concept / Approach:“Has a” corresponds to composition or aggregation (containership). A car “has a” engine; a university “has” departments. The owner object holds references/fields of the component type.

Step-by-Step Solution:

Polymorphism → “is able to behave like many forms” at runtime; not about ownership.Templates (generics) → parameterize types; not a relationship by itself.Containership → models ownership/part-whole → correct.Encapsulation → information hiding; not a relationship type.Inheritance → “Is a/Kind of” relationship, not “Has a”.

Verification / Alternative check:Class diagrams: a filled diamond (composition) or hollow diamond (aggregation) from whole to part is the standard notation.

Why Other Options Are Wrong:They describe other OO concepts not matching ownership semantics.

Common Pitfalls:Confusing inheritance (“is a”) with composition (“has a”).

Final Answer:Containership (composition/aggregation)

Discussion & Comments
No comments yet. Be the first to comment!
Join Discussion