aspose file tools*
The moose likes Beginning Java and the fly likes Java--inheritance,reusability,object oriented design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java--inheritance,reusability,object oriented design" Watch "Java--inheritance,reusability,object oriented design" New topic
Author

Java--inheritance,reusability,object oriented design

Shishir Shivhare
Greenhorn

Joined: Nov 09, 2012
Posts: 7
I am studying inheritance.and i have some confusion in it.
Suppose if a class inherit another class.Will the child class will write the code of its parent class in it when it is converted at machine level or just link it.
What is meaning of reuse of code.Is it copying of code?
If code is reused, i think it will increase coupling then why it is beneficial for object oriented design where low coupling is required?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Shishir Shivhare wrote:
Suppose if a class inherit another class.Will the child class will write the code of its parent class in it when it is converted at machine level or just link it.


There is only one copy of the code.

What is meaning of reuse of code.Is it copying of code?
If code is reused, i think it will increase coupling then why it is beneficial for object oriented design where low coupling is required?


Code reuse means not copying code. It's when you write code once, and use that method, class, or library in multiple situations. And note that the main use of inheritance is not code reuse. It is type implementation and specialization. Code reuse comes along as a natural side effect, when the parent class implements a method in a way that is appropriate for the child class as well. Again, though, we don't inherit from a class just to use its methods. If that's all we want--that is, if we're not making a specialized type of the parent class--then we should just use composition instead of inheritance.
Shishir Shivhare
Greenhorn

Joined: Nov 09, 2012
Posts: 7
Will inheritance increase coupling??If yes then it may effect object oriented design?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Shishir Shivhare wrote:Will inheritance increase coupling??


To some extent, yes, but when used appropriately, the coupling is a natural part of the reason for the inheritance in the first place, and is a negligible cost compared to the benefit garnered by type specialization, abstraction, and polymorphism.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java--inheritance,reusability,object oriented design