Inheritance
When developing software applications the use of
inheritance can greatly reduce development times by allowing the
reuse of code with little or no modification by building on classes
that are already defined and available to the developer. This
is achieved by forming a new class, known as the derived class,
which takes over the attributes of a pre existing class which is
known as the base class. The question is how does this
actually assist the developers to build a project more
efficiently?
Consider a class called Person that contains a
person's name, address, date of birth, sex, and phone number.
Now consider a class called Employee that will contain employee
number, salary, holiday entitlement, employee name, address, date
of birth, sex and phone number. The employee class contains
the same details as the person class with the addition of the
employee number, salary and holiday entitlement. Rather than
creating the employee class from scratch the person class can be
used as base to build on. The employee class will inherit the
pre defined attributes from the person class and the developer can
add the employee number, salary and holiday entitlement to
it.
My Findings
The main issue I have come across when
taking over pre existing projects is that people lose sight of
which class the methods and properties should be located. On
simple class definitions like above it is easy to see why the
person class has the attributes it does and why the employee class
inherits the person class and adds the extra attributes.
However on larger more complex project this can become more
difficult especially when the requirements of a project are
constantly changing. When I have picked up project like this
making the changes to the classes to rectify these miss placed
attributes can be time consuming activity but I have found that it
greatly reduces development time in the future due to there being
less confusion and a greater understanding of how the classes work
together.
What I would like to know is if this lack of sight is a
common development issue or have I been unfortunate with the
projects that I have inherited from other development teams?
Your experiences of this kind of issue would interest me
greatly.