Building on this idea, you could then later create a Human class, and then
make the Employee class a subclass of Human. The effect would be that the Employee
class and all of its derived classes (Clerk, Cashier, Executive, etc.) would immediately
inherit all characteristics and behaviors defined by Human.
The object-oriented development methodology places great stock in the concept of
inheritance. This strategy promotes code reusability because it assumes that one will
be able to use well-designed classes (i.e., classes that are sufficiently abstract to allow
for reuse) within numerous applications.
166 CHAPTER 6 ?– O BJECT-ORIENTED PHP
Polymorphism
Polymorphism, a term originating from the Greek language that means ???having
multiple forms,??? defines OOP??™s ability to redefine, or morph, a class??™s characteristic
or behavior depending upon the context in which it is used.
Returning to the example, suppose that a behavior titled clockIn was included
within the employee definition. For employees of class Clerk, this behavior might
involve actually using a time clock to timestamp a card. For other types of employees,
Programmer for instance, clocking in might involve signing on to the corporate network.
Although both classes derive this behavior from the Employee class, the actual implementation
of each is dependent upon the context in which ???clocking in??? is implemented.
Pages:
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246