aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions with the wording Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions with the wording "appears to" "better than" and other relative quantifier" Watch "Questions with the wording "appears to" "better than" and other relative quantifier" New topic
Author

Questions with the wording "appears to" "better than" and other relative quantifier

Alexandre Leveille
Greenhorn

Joined: Jan 26, 2013
Posts: 12

I have difficulties with these two questions from OCP Java SE 6 Programmer Practice Exams from Bert Bates and Kathy Sierra :

1. Coupling.

Code extract:

Choices (not all shown):
B. Class is well encapsulated
C. The setCity is an example of loose coupling

I said B and C. The study guide says B only. I don't get it. Doesn't having a good encapsulation (private variable and using a setter to modify the state of the object) promote loose coupling??. What is wrong here?



2. Encapsulation

Pseud-code:

Choices (not all shown):
A. These classes appear to have low cohesion
E. These classes appear to have weak encapsulation
F. These classes appear to have strong encapsulation

I said A and F. The guide says A and E. Given that there is a get and a set method, as well as other methods to modify the state of these objects, I was thinking as these classes being encapsulated. Anyway, they certainly appear to, given the pseudo-code. Again, what is wrong here?
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1164
Alexandre Leveille wrote: Doesn't having a good encapsulation (private variable and using a setter to modify the state of the object) promote loose coupling??. What is wrong here?


Loose coupling is at a higher level than at this variable definition.

Regards,
Dan

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

Joined: Jul 09, 2001
Posts: 1164
As Loose coupling says -

In computing and systems design a loosely coupled system is one in which each of its components has, or makes use of, little or no knowledge of the definitions of other separate components.


Regards,
Dan
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 614
Coupling is the relationship between two objects.
It is true that encapsulation promotes loose coupling. But in the Contact class example, there is no relationship with other objects.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 614
For encapsulation, in this case, it is possible that Payroll class can directly access Employee's info (state). This is a weak encapsulation.
To make it strong encapsulated, Employee should have setInfo and getInfo methods. Payroll should access Employee's info via getInfo method instead accessing Employee's info directly.

In Employee class, it is possible that Employee can directly access the DB. It is possible that some DB configurations (DB URL, DB port number, DB username, password) are exposed to Employee!
Instead, Employee should create a DAO object, which encapsulates DB configurations. Then, Employee access the DB via the DAO object.

Similarly,Utilities class accesses the printer directly and printer configurations are exposed to Utilities. Instead,
Utilities class can access to the printer via a printer manager object, for example. This printer manager object encapsulates the printer's configuration.

This is just one way to implement it.
Alexandre Leveille
Greenhorn

Joined: Jan 26, 2013
Posts: 12

Thank you for your answers. I still think these questions are really subject to a debate, but I should be good to understand what they expect on the exam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions with the wording "appears to" "better than" and other relative quantifier
 
Similar Threads
K&B encapsulation concept
Has-A relationship
Encapsulation, coupling and cohesion
Confusing Encapsulation and validation question
OO Concepts - Encapsulation, Cohesion, Coupling