what is ad-hoc pulymorphism?
two types: overloading (defined by progammer) and coercion(defined by language/compiler).
what is universal polymorphism?
Polymorphism is over infinitely many types
There is a unifying, common ground to all the different shapes the polymorphic entity may take
Parametric:
template void Sort(T list) …
Relies on templates/generics
Inclusion:
Base* b = new Derived();
Relies on inheritance
what is strict inheritance?
A limited form of inheritance: extend a given class without touching its code
what’s the connection between strict inheritance and the class parts?
Forge
- The derived class has a new forge
Mill
- The derived class has a new mill
Usually, must invoke the mill of the base class
Protocol
- The derived class can add protocol elements
Behavior
- The derived class implements only the new protocol elements
Structure
- The structure of the derived class is an extension of the base class
pros and cons of strict inheritance?
Benefits of strict inheritance:
1. No performance penalty
Compile-time creature
2. No conceptual penalty
Structured path for understanding the classes
3. Conformance (AKA substitutability)
If a class B inherits from another class A, then the objects of B can be used wherever the objects of A are
used. I.e., B is an A.Drawbacks of strict inheritance:
Not overly powerful…
what are polymorphic variables?
what is up-casting?
casting pointers up the
inheritance hierarchy.
this pointer is up-casted implicitly whenever an inherited method is called.
what is down-casting?
casting pointers and
references down the inheritance hierarchy.
must be done explicitly.
does Java have array subtyping?
yes! in Java, if class Manager is a subtype of class Employee, then Manager[] is a subtype of Employee[]: