Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
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 Jun 4 '13 at 20:44
add comment

migrated from stackoverflow.com Jun 4 '13 at 20:38

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 5 down vote accepted
  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.
share|improve this answer
add comment

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
share|improve this answer
    
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 Jun 4 '13 at 20:16
add comment

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

Aggregate means group together;

  • A1
  • A2
  • B1

Aggregated;

  • A
    • 1
    • 2
  • B
    • 1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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