So polymorphism neither encourages encapsulation nor requires inheritance?
Yes, that's exactly right. You can have polymorphism without inheritance. You can have object orientation without inheritance. (Consider a prototype-based languages such as Self or JavaScript.) Almost no book or tutorial on object orientation explains that well, but that's a failure of imagination at best.
This is not polymorphism, this is overloaded functions...
My code declares two classes with identical interfaces and similar semantics. The classes have no relationship code-wise, neither sharing code nor inheriting from each other or from a common ancestor. Yet the main package treats objects of both classes identically, semantically and code-wise, and it works.
How is that not polymorphism? Where is the overloading?
This is polymorphism.
Yes, your code also shows polymorphism -- specifically sub-type polymorphism. That's not the only type of polymorphism, however, and it's certainly not always the best type.
In reply to Re^5: Understanding 'Multiple Inheritance'
by chromatic
in thread Understanding 'Multiple Inheritance'
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |