File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes HAS-A relationship detail, important topic for OCPJP7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "HAS-A relationship detail, important topic for OCPJP7" Watch "HAS-A relationship detail, important topic for OCPJP7" New topic
Author

HAS-A relationship detail, important topic for OCPJP7

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

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.


OCAJP 7, OCPJP 7
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
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


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

Thanks a lot!
Any other input would be much appreciated!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

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

Joined: Feb 28, 2013
Posts: 226

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

Joined: May 26, 2003
Posts: 31054
    
162

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HAS-A relationship detail, important topic for OCPJP7