I understand that interfaces are not needed in dynamic languages ββlike Python. In Java (or C ++ with an abstract base class), interfaces are a means to ensure that, for example, you pass the correct parameter that is capable of performing a set of tasks.
eg. if you have an observer and an observable, an observable is interested in subscribing to objects that support the IObserver interface, which in turn has a notify action. This is checked at compile time.
There is no such thing as compile time in Python, and method searches are performed at runtime. Moreover, you can override the search using the __getattr __ () or __getattribute __ () methods. In other words, you can pass as an observer any object that can be returned when accessing the notify attribute.
This leads me to the conclusion that interfaces exist in Python - it's just that their enforcement is delayed until they are actually used.
Tomasz Zielinski Jan 23 '10 at 7:19 2010-01-23 19:19
source share