From Python in a Nutshell
super(cls,obj)
returns asuper
-object of objectobj
(which must be an instance of classcls
or of any subclass ofcls
), suitable for calling superclass methods.
super([type[, object-or-type]])
returns a proxy object that delegates method calls to a parent or sibling class oftype
.
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