No, inheritance is not the way to achieve code reuse!(littletutorials.com)

submitted by contourcontour(490) 3 years, 9 months ago

I am not sure how so many people go through so many years of school, which is supposed to make us better at thinking, and they fail to differentiate the “why” and the “how”. During interviews, when I ask their opinion about the purpose of inheritance in OOP, invariably I get this precooked answer (not so nicely expressed): inheritance is the way to achieve code reuse. No it is not!

5 comments |category: |Views: 648

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by MalkirMalkir(96) 3 years, 9 months ago 0

"Inheritance is a mechanism used to achieve categorization and to facilitate polymorphism. Using inheritance you can build a hierarchy of concepts separated in categories at different levels of abstraction. By doing this, you can efficiently use another OOP concept, polymorphism, which allows the same control code to manage all objects in a category even if they are different in their implementation."

http://www.google.com/search?hl=en&q=define%3A+polymorphism&btnG=Google+Search

looks like code re-use to me.

Reply

posted by powerrushpowerrush(3873) 3 years, 9 months ago 0

I agree with what I think the author is trying to say, which is that Inheritance isn't the only or always the best way to get code re-use. The way the article is written and the backstory, IMO, is ineffectively constructed, especially the title.

Reply

posted by JamesEggersJamesEggers(1250) 3 years, 9 months ago 0

I have sat through a number of programming classes across different languages, schools, and instructors and they all fall into the bucket described by this post. The post's main focus is that "why" to use inheritance is missing in most cases. It can be a form of code reuse; however, in many companies, a number of developers will use inheritance for the sake of using it. I've actually worked for a company that said "our code uses OOP techniques, we inherit". Obviously something is a bit wrong in some people's definition as to why to use it. I think the final point that the post is trying to make is that the scope of code reuse should be defined. If you aren't looking at a number of different objects that will use the same methods, then an Interface is probably more beneficial than a base class. If you're looking for overall code reuse (i.e. a company's custom DAL code), then it should be in a framework or assembly and not as a set of base classes that a person can inherit from. It boils down to understanding the "why" of the design and purpose of the code.

Reply

posted by jaffarjaffar(0) 3 years, 9 months ago 0

I think the whole point of the article is to warn against doing inheritance for the sake of reuse. You get reuse with inheritance. But this is not the main purpose or the purpose at all. I agree.

Reply

posted by micahburnettmicahburnett(0) 3 years, 9 months ago 0

http://www.berniecode.com/writing/inheritance/

After reading this article, I think I understand where Daniel was going. Reuse *can* be achieved through inheritance, but it is not the desirable way to do it, given better methods or patterns of doing so — because it limits/traps the developer in cases like the ones mentioned, and actually causes/forces code redundancy.

I agree with @powerrush that the article/title wasn't effective to get the point across, and it seemed to be a flame for the purpose of getting noticed.

Reply

information Login or create an account to comment on this story