Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

when to use inheritance

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manan - 22 Aug 2007 13:33 GMT
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.
william.w.oneill@gmail.com - 22 Aug 2007 14:09 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> 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.
joachim@yamagata-europe.com - 22 Aug 2007 14:49 GMT
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
Chris Dunaway - 22 Aug 2007 15:04 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> 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
Enkidu - 23 Aug 2007 09:55 GMT
>> Hi,
>>
[quoted text clipped - 9 lines]
> 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

Signature

Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?

Yaron Karni - 22 Aug 2007 15:06 GMT
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,
>
[quoted text clipped - 4 lines]
> 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.
Ignacio Machin ( .NET/ C# MVP ) - 22 Aug 2007 15:27 GMT
Hi,

> Hi,
>
[quoted text clipped - 4 lines]
> 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 :)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.