3 ms·
Because two features are different doesn't mean they don't solve the same problem. Here, most of the time, class polymorphism is used to solve problem best sol
by loup-vaillant 16y ago
Because two features are different doesn't mean they don't solve the same problem. Here, most of the time, class polymorphism is used to solve problem best solved with parametric polymorphism (sometimes called genericness).
class Base
Base(int i_init) -- constructor
virtual int f(int param) -- a method
class Inherit1 (extends Base)
int f(int param) -- reimplementation 1
class Inherit2 (extends Base)
int f(int param) -- reimplementation 2
class Inherit3 … (ad nauseam)
We don't need class polymorphism with inheritance, here. We can do simpler:
class Base
Base(int i_init, int f_init(int)) { f =: f_init; … }
int f(int)
Or even simpler:
int f(int i_init, int f_init(int)) // C-like syntax
f: int -> (int -> int) -> int -- Haskell syntax
(And don't tell me that passing function as parameters is weird, or complicated. Functions are typically way simpler than "Objects".)