Re: [correction]an oop question

2022-11-02 Thread Julieta Shem
Dennis Lee Bieber  writes:

> On 2 Nov 2022 09:56:28 GMT, r...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [correction]an oop question

2022-11-02 Thread Alan Gauld
On 02/11/2022 20:21, Dennis Lee Bieber wrote:

>>  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".

But duck typing is a perfectly good implementation of polymorphism.
The term just means that different objects respond to the same
message in different ways. Nothing more, nothing less. Inheritance
just happens to be the most common way of building that, especially
in statically typed languages.

> 
>   I'd implement the example hierarchy as
> 
 class Language:
> ...   def f(self):
> ...   print(self.greeting)

And that would be perfectly valid too.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list