Java Reference
In-Depth Information
An alternative solution would be to give every employee a large manual contain-
ing both the applicable general rules and the rules of their subdivisions. For example,
there might be a 22-page manual for the lawyers, a 21-page manual for secretaries,
and a 23-page manual for marketers. The consolidation might even save a few pages.
So why does the company bother to generate two manuals for every employee?
The main reason has to do with redundancy and maintenance. The 22-page lawyer
manual contains a lot of the same text as the 21-page secretary manual. If a common
rule is changed under the one-manual scenario, all the manuals need to be updated
individually, which is a tedious process. Making the same change to many manuals is
also likely to introduce errors, because it is easy to make the change in one copy but
forget to do it in another.
In addition, there's a certain practical appeal to using the shorter, more specific
manuals. Someone who wants to know all the rules that are specific to lawyers can
simply read the 2-page lawyer manual, rather than combing through a 22-page
lawyer manual trying to spot differences.
There are two key ideas here:
1. It's useful to be able to specify a broad set of rules that will apply to many related
groups (the 20-page manual).
2. It's also useful to be able to specify a smaller set of rules specific to a particular
group, and to be able to replace some rules from the broad set (e.g., “use the pink
form instead of the yellow form”).
An important thing to notice about the categories is that they are hierarchical. For
example, every legal secretary is also a secretary, and every marketer is also an
employee. In a pinch, you could ask a legal secretary to work as a standard secretary
for a short period, because a legal secretary is a secretary. We call such a connection
an is-a relationship.
Is-a Relationship
A hierarchical connection between two categories in which one type is a
specialized version of the other.
An is-a relationship is similar to the idea of a role. A legal secretary can also fill
the roles of a secretary and an employee. A lawyer can also fill the role of an
employee. A member of a subcategory can add to or change behavior from the larger
category. For example, a legal secretary adds the ability to file legal briefs to the sec-
retary role and may change the way in which dictation is taken.
Each group of employees in our example is analogous to a class in programming.
The different employee groups represent a set of related classes connected by is-a
relationships. We call such a set of classes an inheritance hierarchy.
Inheritance Hierarchy
A set of hierarchical relationships between classes of objects.
 
Search WWH ::




Custom Search