I've just started learning python from a video course and in this course as an example of polymorphism this code was provided:
class network:
def cable(self): print('I am the cable')
def router(self): print('I am the router')
def switch(self): print('I am the switch')
class tokenRing(network):
def cable(self): print('I am a token ring network cable')
def router(self): print('I am a token ring router')
class ethernet(network):
def cable(self): print('I am an ethernet network cable')
def router(self): print('I am an ethernet router')
def main():
windows=tokenRing()
mac=ethernet()
windows.cable()
mac.cable()
main()
Now, I don't really think that's a good polymorphism example. I'm not sure that's a polymorphism at all! In fact, if I remove the network
class (and, of course, the inheritance) the code works exactly the same. So I'm thinking that if you don't use the base class then that's not really polymorphism.
Am I right or wrong? Could someone modify this example so it actually presents the gist of polymorphism (i.e. actually makes use of the base class)?