Page 1 of 1

About Question enthuware.ocpjp.v7.2.1248 :

Posted: Thu Sep 12, 2013 11:37 am
by The_Nick
Hi everyone,
Are you sure it's not testing the design view of the thing?
If a class has a list of object, for example:
public class A{
String a= "string";
List<B> listB = new List<>();
}
class B{
}
Design speaking in terms of checking coupling.. does not make sense saying A has a list, whereas it's not correct saying that A has NOT a B since it will have many B potentially.
Also class A has-a String in terms of class design does not make much sense to me.
Do you have a reference asserting these kind of statements?

Thanks in advance.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Fri Sep 13, 2013 8:41 pm
by admin
I am not sure I understand your question correctly. Could you please be a little more clear so that I can help?

thank you,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Sat Sep 14, 2013 10:23 am
by The_Nick
admin wrote:I am not sure I understand your question correctly. Could you please be a little more clear so that I can help?

thank you,
Paul.

Code: Select all

Class A
{
String name =""; 
List<B> list =new ArrayList<>();
}
Class B
{

}
2 points quite straight forward considering the above code:

1) A has a B because it's going to be a list of B, therefore the relation has-a. Instead you say that A has-a list.. which would not be compliant with an Object Oriented Design way to see these relationship.

2) Class A has-a String does not make sense to me. If the scope of the relationship is creating a Object Oriented Design relation has-a. The fact that a class has-a String is certainly true but not critical in terms of coupling.

Furthermore in this http://www.coderanch.com/t/616942/java- ... ation/OCJP link I got confirmed by another user that there is a has-a relationship between the List generic element and the class containing it.

Basically I would like to know why List<B> list = new ArrayList<>(): would not create a has-a relationship A has a B.

Thanks in advance.
Always available for further clarification about the question.

The_Nick.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Sat Sep 14, 2013 10:35 am
by admin
There have been several discussions on this issue. The general consensus is that has-a relationship is based on the type of the variable and not the name of the variable.

I personally do not agree with that and have explained my reasons here: viewtopic.php?f=38&t=1677&hilit=ting

However, it is difficult to argue when someone says it is correct because it is written in a book (irrespective of who wrote it and why). So we decided to go with the consensus and avoid the confusion.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Sun Sep 15, 2013 10:41 am
by The_Nick
Ok for the variable type vs variable name.
What about List<Bla> blaList;..

the link above mentioned (in the previous post) Blon has-a List of Blas

You are saying that "Blon has-a List of Blas." and not that Blon has-a Blas.. is there any documentation available supporting this concept? Coupling speaking it does create a relation with the 2 classes.
It is certainly true that Blon has a list of Blas, and as a consequence Blon has a/or many Blas..

What's your view on it?

Thanks in advance.

The_Nick.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Sun Sep 15, 2013 11:50 am
by admin
Since it has many blas, by extension you could say that it has-a bla and it would be difficult to disagree with that from a purely logical perspective.

My personal opinion is that having having a List of Blas changes the relationship from an OO perspective. I don't consider having multiple as same as has-a. I don't consider List<Bla> same as Bla.

I would suggest you to get other opinions from folks at JavaRanch.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Tue Oct 08, 2013 2:21 pm
by Student
I answered that "Blon has a Bla", having gone through K+B's OCP6 books.

According to Bates and Sierra:
"The phrase translations are “can have” usually means a class has an instance variable, or set of variables" (OCP SE6 Practice Exams, Ch7 Practice Exam 4 Question 56 (Answer)).

Yours unhappily,
Student :(

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Tue Oct 08, 2013 2:42 pm
by admin
Please see the discussion above. Can't comment on what other books say.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Wed Dec 03, 2014 12:52 pm
by SepticInsect
Why is alternative 2 incorrect?

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Wed Dec 03, 2014 8:24 pm
by admin
SepticInsect wrote:Why is alternative 2 incorrect?
Because Toon doesn't have an instance variable of type tang. tang is a variable name in Ting. It is not a type. For has-a, the type of the variable is important not the name of the variable.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Wed Nov 04, 2015 6:38 pm
by evafang2008
I can not understand why B is incorrect? "Toon has-a tang". I think it is correct. Could you please help me clear this?

I compared to Oracle Java SE 7 exam example #2:
http://education.oracle.com/pls/web_pro ... =SQ1Z0_804

2. Given:

class Class1 {
String v1;
}
class Class2 {
Class1 c1;
String v2;
}
public class Class3 {
Class2 c1;
String i3;
}

Which three options correctly describe the relationship between the classes?
A) Class2 has-a i3
B) Class1 has-a v2
C) Class2 has-a v2
D) Class3 has-a v1
E) Class2 has-a Class3
F) Class2 has-a Class1


The correct answer is CDF, the option C and D are similar to this question, why they are correct?
Thank you.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Wed Nov 04, 2015 9:21 pm
by admin
Please go through the discussion above.

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Fri Aug 25, 2017 11:58 am
by horst1a
Sorry, i dont understand this.

Why is answer 1 right ? It shoud say Ting has a tang

Re: About Question enthuware.ocpjp.v7.2.1248 :

Posted: Fri Aug 25, 2017 11:17 pm
by admin
Logically, you are right but there is no consensus on whether the has-a relationship is on the name or the type. As per the reports we have received from exam takers, the questions in the exam consider the relationship to be on the type instead of the name of the variable.


HTH,
Paul.