The Artima Developer Community
Sponsored Link

Design Forum
Help: Confusion about text in Design Pattern by GoF

1 reply on 1 page. Most recent reply: May 5, 2004 9:18 AM by Shashank D. Jha

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Vatsal

Posts: 87
Nickname: vatsal
Registered: Jan, 2004

Help: Confusion about text in Design Pattern by GoF Posted: Apr 4, 2004 11:52 PM
Reply to this message Reply
Advertisement
In the book "Design Patterns" by Gang of Four"

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?

Thanks in advance


Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Help: Confusion about text in Design Pattern by GoF Posted: May 5, 2004 9:18 AM
Reply to this message Reply
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.

Flat View: This topic has 1 reply on 1 page
Topic: Perfect code Previous Topic   Next Topic Topic: Can you help me finish this program.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use