[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [linux] petite info sur phyton
Un morceau de la doc de la version 2.1.
9.5 Inheritance
Of course, a language feature would not be worthy of the name ``class''
without supporting inheritance. The syntax for a derived class definition
looks as
follows:
class DerivedClassName(BaseClassName):
<statement-1>
.
.
.
<statement-N>
The name BaseClassName must be defined in a scope containing the derived
class definition. Instead of a base class name, an expression is also
allowed.
This is useful when the base class is defined in another module, e.g.,
class DerivedClassName(modname.BaseClassName):
Execution of a derived class definition proceeds the same as for a base
class. When the class object is constructed, the base class is remembered.
This is
used for resolving attribute references: if a requested attribute is not
found in the class, it is searched in the base class. This rule is applied
recursively if
the base class itself is derived from some other class.
There's nothing special about instantiation of derived classes:
DerivedClassName() creates a new instance of the class. Method references are
resolved as follows: the corresponding class attribute is searched,
descending down the chain of base classes if necessary, and the method
reference is
valid if this yields a function object.
Derived classes may override methods of their base classes. Because methods
have no special privileges when calling other methods of the same object,
a method of a base class that calls another method defined in the same base
class, may in fact end up calling a method of a derived class that overrides
it.
(For C++ programmers: all methods in Python are effectively virtual.)
Gerd-Christian Michalke wrote:
> Bonjour !
>
> j'avais dernierement une de ces discussions assez inutiles, j'en conviens,
> pour comparer Java/Python (alors que l'un n'a rien, mais alors rien a voir
> avec le second -- sauf une certaine integration avec JPython, Jython).
> Soit.
>
> En fait ja'merais bien utiliser qd meme python pour l'une ou l'autre
> bricole surtout a cause d'une syntaxe claire. Question: esske python
> supporte-t'il le polymorphisme ? Attention: les classes, ca je sais, j'ai
> deja essaye aussi pourfaire de l'heritage. Mais le polymorphysme, le vrai
> avec des methodes virtuelles (ou abstraites, c'est selon) ?
>
> Merci a l'avance
> Gerd
>
> [ Soyez précis dans vos sujets svp afin de déterminer directement ]
> [ le type de demande... ]
> [ Pour vous (dés)inscrire, aller sur http://linuxbe.org/ml.php ]
> [ http://LinuxBe.org Contact: listmaster@linuxbe.org ]
[ Soyez précis dans vos sujets svp afin de déterminer directement ]
[ le type de demande... ]
[ Pour vous (dés)inscrire, aller sur http://linuxbe.org/ml.php ]
[ http://LinuxBe.org Contact: listmaster@linuxbe.org ]