Forums Register Login

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

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 780 times.
Similar Threads
Encapsulation, coupling and cohesion
K&B encapsulation concept
Confusing Encapsulation and validation question
Has-A relationship
OO Concepts - Encapsulation, Cohesion, Coupling
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:30:47.