ABC

python

Abstract Base Classes - Classes de base abstraites

Une classe abstraite, par opposition à une classe concrète, peut posséder des méthodes abstraites. On connait les paramètres des méthodes abstraites, amis on ne donne pas de corps (on de donne pas les instructions qui seront exécutées quand la méthode abstraite sera abstraite).

Au moins une méthode abstraite => classe abstraite

Le module collections introduit entre autres un certain nombre de classes de base abstraites:

ABC Inherits from Abstract Methods Mixin Methods
container   __contains__  
Hashable   __hash__  
Iterable   __iter__  
Iterator Iterable __next__ >__iter__
Sized   __len__  
Callable   __call__  
Sequence Sized, Iterable, Container __getitem__ __contains__, __iter__, __reversed__, index, and count
MutableSequence sequence __setitem__, __delitem__, insert Inherited sequence methods and append, reverse, extend, pop, remove, and __iadd__
Set Sized, Iterable, Container   __le__, __lt__, __eq__, __ne__, __gt__, __ge__, __and__, __or__, __sub__, __xor__, and isdisjoint
MutableSet Set add, discard Inherited Set methods and clear, pop, remove, __ior__, __iand__, __ixor__, and __isub__
Mapping Sized, Iterable, Container __getitem__ __contains__, keys, items, values, get, __eq__, and __ne__
MutableMapping Mapping __setitem__, __delitem__ Inherited Mapping methods and pop, popitem, clear, update, and setdefault
MappingView Sized   __len__
ItemsView MappingView, Set   __contains__, __iter__
KeysView MappingView, Set   __contains__, __iter__
ValuesView MappingView   __contains__, __iter__

» Glossaire du langage python