OCPJP 6
Boris Mechkov wrote:Consider the following...
Isnt't validation part of how well the a class is encapsulated?
Dennis Deems wrote:
Boris Mechkov wrote:Consider the following...
Isnt't validation part of how well the a class is encapsulated?
Not really. The opportunity to perform validation is a benefit of designing a strongly encapsulated class. But it is still strongly encapsulated even if we don't actually perform any validation.
OCPJP 6
public getter, setter methods with private instance vars..
Second issue that confused me was the fact that setName() does not do any validation to what "name" we could put in there. setCity does validation, but setName does not, so shouldn't setCity() have better encapsulation than setName()? Isnt't validation part of how well the a class is encapsulated?
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan wrote:Hello Boris,
I want to assume that line 5 of your code is a typographical error otherwise the answer will be compilation fails. That said
public getter, setter methods with private instance vars..
This is very correct because if the methods are 'default' then it will be package access level, I dont want to call it 'Tight-Encapsulation'
who knows?.
Second issue that confused me was the fact that setName() does not do any validation to what "name" we could put in there. setCity does validation, but setName does not, so shouldn't setCity() have better encapsulation than setName()? Isnt't validation part of how well the a class is encapsulated?
The purpose of encapsulation -amongs others- is to protect instance variable from DIRECT access by making them private and providing public getter, setter methods to access them. To the best of my knowledge, validation has nothing to do with encapsulation.
OCPJP 6
OCPJP 6
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ikpefua Jacob-Obinyan wrote:Boris Have you noticed that your knowledge is being tested on the concepts of OO design? if you take a second look at the first question you posted you will find out, lets try out some analysis:
-encapsulation; A mechanism for restricting access to some of the object's components; 'private' instance variables; reason why option b is correct.
-loose coupling; the degree to which classes know of themselves; class User extends Contact is loosely coupled because it has NO direct access to the instance variables in class Contact and here is where it is IMPORTANT loose coupling involves TWO classes, in this senario we have ONLY ONE; reason why option c is wrong.
-Option d is WRONG because they have the same 'default' restriction so one is NOT better encapsulated than the other.
-Cohesion; refers to how well the purpose of a class is focused; a good example is the java.io package the classes there all have specific purposes e.g File class ONLY deals with Files and the Writer class ONLY deals with writing to files.
Option e is WRONG because it is refering to methods and NOT 'how-well-the-purpose-of-a-class-is-focused'.
Let me know if you have futher doubts, I will be pleased to assist.
OCPJP 6
Paper jam tastes about as you would expect. Try some on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|