News for hackers. Stuff that matters.
Re:Interfaces and Protocols in Python by nine_k on Friday March 19, 2021 @10:02PM (#26520124)
Depends on the language.

In Java, you have to explicitly mark a class as conforming to an interface inside the class's declaration. You need to have the source and modify it.

In Haskell, you mark a type as conforming to an interface (called typeclass) by adding functions that operate on its instances and implement the interface's requirements. You can do it anywhere, and write an implementation for an existing type, which is normal practice.

In Python, you cannot easily add interface conformance, but possibly you can make a trivial subclass of the desired class, and mark it as conforming to the desired interface (Protocol), without modifying the source.

There are no comments on this comment yet.