dimanche 5 novembre 2017

How does the `super` class implement the proxy design pattern?

From Python in a Nutshell

super(cls,obj) returns a super-object of object obj (which must be an instance of class cls or of any subclass of cls), suitable for calling superclass methods.

From http://ift.tt/2hgIF75

super([type[, object-or-type]]) returns a proxy object that delegates method calls to a parent or sibling class of type.

A comment by Martijn Pieters says that the return object of super(cls,obj) is an example of the proxy design pattern.

In Design Pattern by Gamma et al, the proxy design pattern is implemented by inheriting the class of the subject of proxy. But I found that super class is inherited only from object, and not from the subject of proxy, which is "a parent or sibling class of type". So I wonder how the super class implement the proxy design pattern? By duck typing?

Thanks.

Aucun commentaire:

Enregistrer un commentaire