• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java--inheritance,reusability,object oriented design

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will inheritance increase coupling??If yes then it may effect object oriented design?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic