[correction]an oop question
Julieta Shem
jshem at yaxenu.org
Wed Nov 2 20:35:01 EDT 2022
Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:
> On 2 Nov 2022 09:56:28 GMT, ram at zedat.fu-berlin.de (Stefan Ram) declaimed
> the following:
>
>
>> Now, in the next program, I have removed the subclassings,
>> there is no inheritance from the base class "Language"
>> anymore. Yet the polymorphism in "f" still works. And this
>> shows that in Python we do *not* need subclassing/inheritance
>> for polymorphism!
>>
> To me, that is not really an example of polymorphism, but more an
> example of Python's "duck typing".
>
> I'd implement the example hierarchy as
>
>>>> class Language:
> ... def f(self):
> ... print(self.greeting)
> ...
>>>> class English(Language):
> ... def __init__(self):
> ... self.greeting = "Good Morning"
> ...
>>>> class French(Language):
> ... def __init__(self):
> ... self.greeting = "Bonjour"
> ...
>>>> English().f()
> Good Morning
>>>> French().f()
> Bonjour
>
> ... with no explicit /function/ for greeting -- it's just an attribute
> set in each subtype, inheriting the "f" function for printing.
A popular encyclopedia would enumerate various specifications of the
word polymorphism. Ad hoc polymorphism, parametric polymorphim, subtype
polymorphim et cetera.
``One of the most difficult matters in all controversy is to
distinguish disputes about words from disputes about facts: it ought
not to be difficult, but in practice it is.''
-- ABC of Relativity, Bertrand Russell, chapter 12, 1925.
``What's in a name?''
-- Romeo and Juliet, Shakespeare, 1597.
More information about the Python-list
mailing list