design-patterns/behavioral/observer/subject.py
Ruidy c8cc1f47b8
Observer (#20)
* doc: create package & update general TOCs

* doc: add documentation

* add code example

* reformat using black
2020-10-06 08:25:18 +02:00

35 lines
714 B
Python

from abc import ABC, abstractmethod
from behavioral.observer.observer import Observer
class Subject(ABC):
"""
The Subject interface declares a set of methods for managing subscribers.
"""
@property
@abstractmethod
def state(self) -> int:
pass
@abstractmethod
def attach(self, observer: Observer) -> None:
"""
Attach an observer to the subject.
"""
pass
@abstractmethod
def detach(self, observer: Observer) -> None:
"""
Detach an observer to the subject.
"""
pass
@abstractmethod
def notify(self) -> None:
"""
Notify all observers about an event.
"""
pass