Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Has-A relations must be on the same inheritance hiearchy

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the k&B Practice Exams.






Answer (for Objective 5.5):
 B, E, and F are correct statements about the code.
 A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.
D is similarly incorrect because MyApp doesn’t “have” a Mungeable as part of its state.


When answering the above question i selected the option that says MyApp has-a Employee.
The book says that this is wrong because Employee and MyApp are not on the same inheritance tree. Is this correct?

I was not aware that the classes are supposed to be on the same inheritance tree for a has-a relationship.

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you print the actual question and all possible answers please?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3165
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HAS-A indicates that the class contains some reference at the instance level.
In the example- Employee is a local variable used in public static void main. Its not really part of MyApp class.
And HAS-A doesnt depend on the inheritance hierarchy- because its composition.

Which is the source you are using for this question and solution?
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:Can you print the actual question and all possible answers please?


I have updated the question.
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:HAS-A indicates that the class contains some reference at the instance level.
In the example- Employee is a local variable used in public static void main. Its not really part of MyApp class.
And HAS-A doesnt depend on the inheritance hierarchy- because its composition.

Which is the source you are using for this question and solution?


It was a question from the K&B practice exams. The description given for the answer is

Answer (for Objective 5.5):
 B, E, and F are correct statements about the code.
 A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.
D is similarly incorrect because MyApp doesn’t “have” a Mungeable as part of its state.





 
Mohamed Sanaulla
Saloon Keeper
Posts: 3165
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O. Ziggy wrote: A and C are incorrect because the MyApp class “uses” the Employee class, but MyApp isn’t
in Employee’s class hierarchy, and MyApp doesn’t “have” an Employee as part of its state.


I think you are confused with this statement right?

The statement above is stating the reasons why A and C are incorrect. The- "the MyApp class “uses” the Employee class, but MyApp isn’t in Employee’s class hierarchy" is justification for A not being correct and the other statement is a justification for C not being correct.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Totally agree Mohamed.
 
Abdullah Mamun
Ranch Hand
Posts: 99
Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear how "E. The code is loosely coupled." is a correct answer.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic