Skip to content

require-explicit-service-contract

Require an explicit contract for a service that invokes a retained collaborator.

Why

A one-operation service can orchestrate other services without declaring the contract that callers consume and implementations and fakes satisfy.

Fix

Declare a focused ABC or Protocol covering the service operations and make that contract explicit on the implementation; reuse an existing contract instead of adding a nominal duplicate.

Examples

Before — flagged One service operation still needs its contract
app/service.py
class OrchestratorService:
def __init__(self, worker: Worker) -> None:
self.worker = worker
def run(self) -> None:
self.worker.run()
After — preferred The service declares its operation
app/service.py
from abc import ABC, abstractmethod
class Runner(ABC):
@abstractmethod
def run(self) -> None: ...
class OrchestratorService(Runner):
def __init__(self, worker: Worker) -> None:
self.worker = worker
def run(self) -> None:
self.worker.run()