ABC (Python Inheritance)
from abc import ABC, abstractmethod
class BaseService(ABC):
@abstractmethod
def run(self) -> str:
pass
Protocol (Flexible, NO inheritance)
Define protocol:
from typing import Protocol
class EmbeddingProvider(Protocol):
def embed(self, text: str) -> list[float]:
...
Class that matches shape, then works:
class OpenAIEmbed:
def embed(self, text: str) -> list[float]:
return [0.1, 0.2]