I know Aggregation is a has-a relationship, but I encountered a question in a test which did not make sense (and had grammatical mistakes as well)

Which of the following statements correctly describe the concept of aggregation in OOP?

  • A Splitting a class into a several sub classes
  • B Creating one piece of code that works with all similar objects
  • C Accessing data only through methods
  • D Combining several classes to create a new class
  • E Creating a new class from an existing class

I think;

  • A Could be true.
  • B Sounds like inheritance.
  • C Seems like property.
  • D Could be true.
  • E Could be true.

I'm uncertain how the has-a relationship translates into actual code in these statements. Any ideas?

  • 2
    I think I've seen this question before, was it an IKM test? It seems worded specifically to confuse, how someone can be proud of writing this is beyond me. I too would go with D but I'll read the responses with interest.
    – PeteH
    Commented Jun 4, 2013 at 20:44

3 Answers 3

  1. Aggregation is a Whole-Part relationship. And so it is also a has-a relationship.
  2. By definition the part objects can have life cycles of their own, independent of the "whole" object.
  3. Composition is aggregation with a twist. It adds the idea that the constituent parts do not/cannot/should not exist without the whole. The parts have no real meaning or functionality outside the whole. And conversely the whole is incomplete or cannot function properly without its parts.
  4. A is wrong because this is either inheritance or composition. Depends on how technically we read "sub class." Either way, its not aggregation.
  5. B is wrong, that is polymorphism, implying the idea of coding to interfaces
  6. C is wrong, that is encapsulation; in its pure form I'd say. Using a class via what it does - methods - vice accessing its state properties.
  7. D is the best answer.
  8. E is wrong, it simply does not meet the definition of aggregation.

Hmm, Based on this wiki, I would go with D. It seems that the intent was to 'Combining several classes to create a new class', means, to include several classes.

Clarification: I am not sure though. Its confusing because the Answer could be read as the opposite of sub-classing. Where one takes a bunch of sub classes and creates one monster object with all its properties. In which case all the properties are lost on the objects destruction.

My quick read:

  • A: Sounds like Sub-classing
  • B: Sounds like Polymorphism or something similar
  • C: Sounds like property
  • D:
  • E: Sounds like inheritance
  • Yeah I read the wiki earlier and thought multiple answers were possible, but, yeah, now I also think D seems like the closest, given the confusing wording.
    – Qash
    Commented Jun 4, 2013 at 20:16

I think the answer they want is "D - Combining several classes to create a new class."

Aggregate means group together;

  • A1
  • A2
  • B1


  • A
    • 1
    • 2
  • B
    • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.