Author Topic:   Encapsulation
Alkesh Nandanwar
ranch hand
posted March 24, 2000 10:21 PM             
Which is the advantage of encapsulation?
A.Only public methods are needed.

B.No exceptions need to be thrown from any method.

C.Making the class final causes no consequential changes to other code.

D.It changes the implementation without changing the interface and causes no consequential changes to other code.

E.It changes the interface without changing the implementation and causes no consequential changes to other code.


I think the correct answer is c)
Any comments
Alkesh

veena
unregistered
posted March 24, 2000 11:27 PM           
Correct answer is d.
D.It changes the implementation without changing the interface and causes no consequential changes to other code
because encapsulation is meant for hiding your implementation
(code inside your method).your classes are used only through the interfaces(methods name) you provide.so you can change the code inside your method without actually affecting the interface

making a class final is related to another feature of oops called inheritance

maha anna
bartender
posted March 25, 2000 12:56 PM             
Alkesh,
A very good encapsulation implies keeping all states(member vars) as private, and all methods as public. Messages are passed between objects through their methods. Since all member vars are kept private (encapsulated) within the class itself, all other objects can talk to this object only through their public methods. Outsider classe objects CAN NOT change the member vars. So when you want to change the implementation of a method you can always do it without affecting the other parts of the program which uses this class. Which means you can easily change the implementaion at any time without affecting the public interface methods. Outsider classes don't even know that the implemantaion has been changed in the class which uses tight encapluation because outsider classes were never allowed to access the member vars. So changing the implementation makes no difference as far as outsider classes are concerned.

This info can be useful to answer the above qstn. You can also easily say which choices in the above qstn are related to encaptulation.

Please confirm us whether you are convinced with your answers and the reasoning for the same.

regds
maha anna

[This message has been edited by maha anna (edited March 25, 2000).]

Alkesh Nandanwar
ranch hand
posted March 25, 2000 01:09 PM             
hi Anna,
I totally agree with you now.
It changes the implementation without changing the interface and causes no consequential changes to other code.
This is the right option
Alkesh

maha anna
bartender
posted March 25, 2000 01:14 PM             
Yes. Your ans is correct and so quick also.
regds
maha anna

Rolf Weasel
ranch hand
posted March 25, 2000 05:42 PM             
This question is one of the sample questions at the sun site and i must say it worries me a bit. The grammer is atrocious!
D.It changes the implementation without changing the interface and causes no consequential changes to other code.
Sun says they got all sorts of language experts going thru all questions in the real exam. One would think the few sample questions would at least make sense.

[This message has been edited by Rolf Weasel (edited March 25, 2000).]

maha anna
bartender
posted March 25, 2000 06:18 PM             
Rolf,
Which part of the answer worries you and why? Is that the word interface ? If so, if you read the qstn in this particular context it makes sence.( for Maha atleast. . )
regds
maha anna

Rolf Weasel
ranch hand
posted March 25, 2000 11:31 PM             
'It' changes the implementation without changing the interface and causes no consequential changes to other code. Encapsulation does not change implementation, a programmer does! and changing the interface can't `cause consequential changes to the other code', it can only `require consequential changes to the other code'!
if there's questions worded like this on the actual exam, gawd help us!

|