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