DenkzeitWiki

Suchen:

Aktuelle Änderungen Printable View Änderungen Bearbeiten

CodeSmells > CodeIsData > Boilerplate > LatentTyping > JohnMcCarthy > RecentChanges > SearchWiki > PascalCostanza > AbstractionsLeak > PythonGenerators > WhitespaceInPython > MultipleInheritance > FirstClassFunctions > SuccinctnessIsPower > ModelViewController > OnlyPublicFieldsInPython > PythonAbstractBaseClassesClear Trail
Main /

Python Abstract Base Classes

Python3000

StaticVsDynamicTyping
Interfaces
MultipleInheritance

interfaces were more important than type checking. Personally, I think they're interconnected: interfaces make much more sense if you can also declare the argument types of the methods, and argument type declarations in Python are unthinkable without a way to spell duck types -- for which interfaces are an excellent approach.[...]

A few more arguments against ABCs: they seem the antithesis of duck typing. Using ABCs for type declarations suggests that isinstance() is used for type checking, and even if reality is not quite that rigid, this suggestion would be leading people into the wrong direction.

ABCs also allow, nay, encourage, "partially abstract" classes -- classes that have some abstract methods and some concrete ones. Of course, such a class as a whole is still abstract, but the resulting mixture of implementation and interface complexifies the semantics.


The normal Python approach is currently to just rely on signature-based polymorphism -- use inheritance to share implementation, but if you have no implementation to share, there's no real reason to inherit.
[...]If you do have any useful features -- most often Template Method design patterns -- to share among (some of) your concrete classes, then by all means use inheritance for that. But, otherwise, I think that keeping documentation in comments and docstring, and using other language constructs (including inheritance) for substantial purposes and not "just to document things", is a preferable approach. AlexMartelli


Edit - BackLinks - Tags - Page Hist - Print - Changes - Home - Orphans - Help

Zuletzt geändert am 20.09.2008 09:24 Uhr und seit 7. April 2005 1717 aufgerufen.