pythonadvanced

Abc Abstract

Advanced Python pattern: abc-abstract

python
from abc import ABC, abstractmethod

class Storage(ABC):
    @abstractmethod
    def save(self, key: str, value: str) -> None: ...

class DictStorage(Storage):
    def __init__(self):
        self._db: dict[str, str] = {}

    def save(self, key: str, value: str) -> None:
        self._db[key] = value

s = DictStorage()
s.save('user:1', 'alice')
print('saved')

Use Cases

  • advanced programming
  • patterns

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.