Polymorphism
Polymorphism is another important concept in the world of object-oriented programming, and is relatively simple to understand.
Polymorphism occurs as a side effect of inheritance. Essentially, it means that you can treat a child object and its inherited methods and properties in exactly the same way you would treat the parent object's methods and properties.
Consider the following code example, in which we output the name property of each product using the objects we have instantiated in Listing 4.4.
<cfoutput> Book Name: #objBook.getName()#<br /> DVD Name: #objDVD.getName()# </cfoutput>
Listing 4.5 Displaying each product name
All of our child objects inherited the getName()
method from within our parent object, the Product Base class. In the previous code example, each child object calls the same inherited method, but returns a different result for each call.
Essentially, this means that the inherited method is polymorphic, as it behaves in exactly the same...