r/Python • • Feb 12 '23

Resource Python Interfaces: Choose Protocols Over ABC

https://levelup.gitconnected.com/python-interfaces-choose-protocols-over-abc-3982e112342e
64 Upvotes

20 comments sorted by

View all comments

138

u/[deleted] Feb 12 '23

Protocols and abstract classes are not interchangeable. You cannot simply choose one over the other. There is a substantial difference: abstract class ensures that an implementation meets certain requirements when a subclass is declared, while protocol checks if an instance meets certain requirements when it's being used. They are different in the same way as "They are of the same kind" and "There are things that both of them can do".

Please, don't confuse people with such articles.

0

u/[deleted] Feb 12 '23

[deleted]

2

u/[deleted] Feb 12 '23

You are confusing abstract and concrete inheritance, I believe.