when to use inheritance

  • Thread starter Thread starter Manan
  • Start date Start date
M

Manan

Hi,

i'm new to OOP concept. in college days i have read lots of good
things about "inheritance" but does any one uses this concept in real
life project ? or can some one tell me when it will be beneficial to
use inheritance?? its now almost 1 yr i'm in to the programming world
but i haven't heard that anyone in my organization uses it. it will be
great if someone can shade some light on this topic.
 
Hi,

i'm new to OOP concept. in college days i have read lots of good
things about "inheritance" but does any one uses this concept in real
life project ? or can some one tell me when it will be beneficial to
use inheritance?? its now almost 1 yr i'm in to the programming world
but i haven't heard that anyone in my organization uses it. it will be
great if someone can shade some light on this topic.

I'm confused, are you using C#? I'm assuming you are since you posted
to this group. The entire .NET framework uses inheritance.

The uses for inheritance are well beyond a post on a newsgroup. My
favorite book which taught me a lot, including the value of
inheritance, is Design Patterns. It's worth a read.

To answer your question, we use inheritance and polymorphism
extensively in our 3+ million line code base.
 
Hi Manan,
i'm new to OOP concept. in college days i have read lots of good
things about "inheritance" but does any one uses this concept in real
life project ? or can some one tell me when it will be beneficial to
use inheritance?? its now almost 1 yr i'm in to the programming world
but i haven't heard that anyone in my organization uses it. it will be
great if someone can shade some light on this topic.

As for GUI programming: just try to build a Windows form from scratch
and you'll know what inheritance can do for you ;-).
Or less dramatic: if you use drag-and-drop boxes very often (eg. when
you want to put files in batch),
you might consider one day to write your own user control which you
can use as a "template",
so you don't have to re-write the code each time you are in need of
one.

As for logics programming: in an ideal world you would have the time
to think of a highly abstracted class, implement it, and then derive
new classes from it
each time you would add a new feature. As for myself, I had to
go through quite some catching up with deadlines, before I could do
some
real refactoring and abstraction work, but in the end it really pays
off to
have all your classes neatly organised so you know which objects you
can re-use
without much of an effort.

An example: I had a monolithic search algorithm object that would do
things when a match occured.
You would have to build a search tree, and then define the actions to
be taken when a match occured.
Since the requirements for the actions and the search tree varied as
time passed, I made a new implementation
with event handlers. I made a very basic base class for which you
could easily override the event handlers.
Some more time passed and all of a sudden an extensive deal of state
information (match positions, action taken, etc.) had to be stored,
so I just extended the object a little further... This was easily done
since all the code was already there.

The advantage is that you can still use the simple version when
required, while you have the more advanced and specialised branches
at practically no cost. The disadvantage is that you have to make sure
(and work on it!) that your base class is really really stable.

Regards,
Joachim
 
Hi,

i'm new to OOP concept. in college days i have read lots of good
things about "inheritance" but does any one uses this concept in real
life project ? or can some one tell me when it will be beneficial to
use inheritance?? its now almost 1 yr i'm in to the programming world
but i haven't heard that anyone in my organization uses it. it will be
great if someone can shade some light on this topic.

In addition to the other post, any time you create a new form in C#,
you are using inheritance. Your form class inherits from the base
System.Windows.Forms.Form class. So, yes, inheritance is extensively
used.

Chris
 
Inheritance is one of the most important things in object oriented world.
Almost you cannot code any conceptual object without using it, using
inheritance assure the code is not a script, help for generic code, element
encapsulation objects and reusing of code.

So, start using it.

In Fact, If you write a code with c# (if?) so be sure you used inherited
object.

Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
 
Hi,

Manan said:
Hi,

i'm new to OOP concept. in college days i have read lots of good
things about "inheritance" but does any one uses this concept in real
life project ? or can some one tell me when it will be beneficial to
use inheritance?? its now almost 1 yr i'm in to the programming world
but i haven't heard that anyone in my organization uses it. it will be
great if someone can shade some light on this topic.

Of course you use it everyday.
I agree with you though that there are people working in C# that do not make
use of it. They just use encapsulation to put methods inside the classes and
that's it.
Of course the code is not that good :)
 
Chris said:
In addition to the other post, any time you create a new form in C#,
you are using inheritance. Your form class inherits from the base
System.Windows.Forms.Form class. So, yes, inheritance is extensively
used.
Surely any time you use a class (any class) it inherits from the Object
class?

Cheers,

Cliff
 
Hi Joachim,

Thanks for your information regarding Inheritance.
Are you working in Philips Hamburg.

Regards,
Reshmi B
 
Back
Top