protocol
Domain: Validation Typing
π― Motivation
Protocol defines a structural interface: any class with the right methods automatically satisfies it, no inheritance needed. This is called duck typing with static checking, giving flexibility and safety together.
π Concrete Example
class Readable(Protocol): def read(self) -> str: ... means any class with a read() -> str method is accepted, whether it is a file, socket, or custom stream.
π Analogy
Protocol is like a job description: βmust be able to drive.β Any person who can drive qualifies, regardless of whether they learned at the same driving school (base class).