Object-Oriented Python by Irv Kalb

Object-Oriented Python by Irv Kalb

Author:Irv Kalb [Irv Kalb]
Language: eng
Format: epub, mobi, pdf
Publisher: No Starch Press
Published: 2022-01-25T00:00:00+00:00


A Classic Example of Polymorphism in Programming

In terms of OOP, polymorphism is about how client code can call a method with the exact same name in different objects, and each object will do whatever it needs to do to implement the meaning of that method for that object.

The classic example of polymorphism is to consider code that represents different types of pets. Let’s say you have a collection of dogs, cats, and birds, and each understands some basic commands. If you ask these pets to speak (that is, you send the “speak” message to each), the dogs will say “bark,” the cats will say “meow,” and the birds will say “tweet.” Listing 9-1 shows how we might implement this in code.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.