Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HAS-A relationship detail, important topic for OCPJP7

 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Having a class A which has a list of B as the following code displays:



I have two questions regarding this code:

1) Is it correct saying that A has-a B? ( I know that A has a list of B, however in terms of coupling it does create a relationship has-a)

2)Again in terms of coupling, would it make sense to say that B has- a String? (I know that B has a String as a field, however again considering in terms of coupling, saying that a class HAS-A String does not really help a programmer in OO design, I think would make sense only for real Classes like B has a A, not for wrapper classes ).

I would be glad to know what you guys think about it.
Thanks in advance.

 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nick,

Rob Spoor said the following at HAS-A relationship? -

arrays or Collections (List, Set, etc) of the variable type also specify a HAS-A relationship, even though it's grammatically not HAS-A but more HAS-MULTIPLE



Regards,
Dan

 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!
Any other input would be much appreciated!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick,
Has-A isn't the same thing as coupling. I think you are confusing matters by trying to think about coupling at the same time as has-a. For example:

This code has coupling, but not has-a.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Nick,
Has-A isn't the same thing as coupling. I think you are confusing matters by trying to think about coupling at the same time as has-a. For example:

This code has coupling, but not has-a.


Well having an instance member of B in class A ties the 2 classes together, isn'it? However what would you thing about the following:


If you had a list of possible choices like: (select all that applies)
a) A has-a B
b) A is-a B
c) A extends B
d) A has-a List

Would you select only d) or also a)?

Thanks in advance.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So guys any new opinions concerning this topic? It's just that tomorrow I have the exam and I would hate missing a score on this.
Cheers.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say just D. But it's a matter of semantics. I didn't get something tricky like that when I took the exam. Plus the real exam tells you how many answers are correct so that gives another clue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic