SCJP2. Please Indent your code using UBB Code
• Sun Certified Programmer for Java 2 Platform (SCJP2)
• IBM Certified Professional for Object Oriented Analysis and Design with UML
• IBM Certified System Administrator for WebSphere Application Server v5.0
• Certified Business Analysis Professional (CBAP®)
Originally posted by Vikrama Sanjeeva:
Hi,
As i remember GoF descibes the reason.It was something like this....that Inheritence breaks encapsulation b/c subclass expose the parent class methods and properties.Therefore Parent's class encapsulation is breaked!.
Note:For more clear reason see GoF.
Bye,
Viki.
Originally posted by Jose Botella:
Why inheritance breaks encapsulation? Isn't encapsulation achieved via private members? If so, private members aren't accesible from subclasses either.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
.Originally posted by Roshan :
but foo in A is declared protected then B will break because you cannot override foo in B with more restrictive visibility than in A.
Originally posted by Junilu Lacar:
Here's the paper by Alan Snyder that is often referenced: http://www.cs.colorado.edu/~diwan/class-papers/snyder.pdf
Also, Joshua Bloch discusses concrete Java examples in his book "Effective Java Programming Language Guide" (Items 14 & 15)
Originally posted in
Mark Grand, Patterns in Java: a catalog of reusable design patterns illustrated with UML, Volume 1. - 2nd ed., 1999, John Wiley & Sons
p.55 "There is no way effectively hide methods or variables that are inherited from a superclass"
Originally posted in
Mark Grand, Patterns in Java: a catalog of reusable design patterns illustrated with UML, Volume 1. - 2nd ed., 1999, John Wiley & Sons
"An even more serious problem is that client classes can call the public methods of the utility superclass, which defeats its encapsulation"
Encapsulation is a technique for minimizing interdependencies among separately-written modules by defining strict external interfaces. The external interface of a module serves as a contract between the module and its clients, and thus between the designer of the module and other designers. If clients depend only on the external interface, the module can be reimplemented without affecting any clients, so long as the new implementation supports the same (or upward compatible) external interface.
AntyDigital
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|