• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HAS-A relationship detail, important topic for OCPJP7

 
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot!
Any other input would be much appreciated!
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic