In section 1.6(Page 19, How Design Patterns solve design problems), they say
"Parent classes often define at least part of their subclasses's physical representation, Because inheritance exposes a subclass to details of its parent's implementation, it is often said that "inheritance breaks encapsulation""
1) What does authors exactly mean by above paragraph?
2) In what cases parent class define atleast part of subclass physical representation?(IMHO it happens all the time, parent classes form the basis of subclass representation).
Can some one throw more light on this issue and explain what authors really means by "Inheritance breaks encapsulation" and in what cases all this happens?
Ok Let us view it like this. You model a base class when set of derived classes have common behaviour. Now what is that behavior, this could be "Manufacturer name for each of the Car (Car as base class for Mercedes!!) and also it could be price of each of the car manufactured.
So above example makes clear that car may be modelled as base class for all differnt models of the car maufacturer and each of the car has attached with it manufacturers name (commmon to all simple lets consider single enterprise) and price (each car has a price). Now price part depends on the particular model of the car. So in a way inheritance (price of base class car) is or has to be implemented by derived car ).
So it is also clear that it doesnt happens all the time. Depends on the design of the system
By inheritance what u achieve ?? base class datas (information) and implementation (behaviour). So isn't it that encapsulation of informations within a class (base class) is available to derived class ?? so in a way inheritance breaks the encapsulation of base class.