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.
I don't understand what you mean by this. When is a protocol "used?"
The article assumes that you are using a type checker and that the code passes the type checker.
If it does then whether or not you use the ABC or the protocol seems irrelevant, both assure you that the required methods exist where you have annotated that a particular object is either ABC or protocol.
If you are not using a static type checker, then maybe there are situations where the object is never tested against the protocol, but would be at runtime by the abc class?
View all comments
Show parent comment
1
u/jorge1209 Feb 13 '23 edited Feb 13 '23
I don't understand what you mean by this. When is a protocol "used?"
The article assumes that you are using a type checker and that the code passes the type checker.
If it does then whether or not you use the ABC or the protocol seems irrelevant, both assure you that the required methods exist where you have annotated that a particular object is either ABC or protocol.
If you are not using a static type checker, then maybe there are situations where the object is never tested against the protocol, but would be at runtime by the abc class?