3 ms·
Bar and Baz can be a Foo without necessarily being derived classes that inherit from base class Foo. In Python defining function f is enough for a class to be
by HelloNurse 6y ago
Bar and Baz can be a Foo without necessarily being derived classes that inherit from base class Foo.
In Python defining function f is enough for a class to be a Foo (and Foo could not exist at all in code, replaced by the informal concept that a type with method f is a Foo)
In languages like Java, there are interfaces, which are not classes at all and describe with tedious compiler-friendly explicitness what a class needs to qualify as a Foo.
On a different variability axis, sometimes you need to declare interface implementations explicitly ("class Bar implements Foo" in Java) and sometimes not (Python duck typing, C++ concepts)