Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

4.1. Polymorphism

The word polymorphism derives from ancient Greek, where poly means many and morph means form. In programming languages, polymorphism is the idea that values of different data types can be treated in the same way. Often, this is manifested via class inheritance, where classes in a hierarchy can have methods of the same name. When such a method is called on an object, the right code is executed at runtime depending on which class the object is an instance of. There are various ways of achieving polymorphic behavior, and inheritance is only one such way. The diagram in figure 4.1, taken from a paper published by Luca Cardelli in 1985 (http://lucacardelli.name/Papers/OnUnderstanding.pdf), shows a high-level classification of polymorphism.

Figure 4.1. There are several types of polymorphism. Subtype polymorphism (a form of inclusion) is the most common (Java/C++) kind of polymorphism but is only one of several.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial