feat: storage.py is a tutorial for Interface
This commit is contained in:
parent
16497f059c
commit
ffc1c06a2d
27
src/tutorial/class/storage.py
Normal file
27
src/tutorial/class/storage.py
Normal file
@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class Storage(ABC):
|
||||
@abstractmethod
|
||||
def save(self, key: str, value: str) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def load(self, key: str) -> str:
|
||||
pass
|
||||
|
||||
|
||||
class MemoryStorage(Storage):
|
||||
def __init__(self) -> None:
|
||||
self.storage = {}
|
||||
|
||||
def save(self, key: str, value: str) -> None:
|
||||
self.storage[key] = value
|
||||
|
||||
def load(self, key):
|
||||
return self.storage[key]
|
||||
|
||||
|
||||
s = MemoryStorage()
|
||||
s.save("randomkey", "My Value")
|
||||
print(s.load("randomkey"))
|
||||
Loading…
x
Reference in New Issue
Block a user