mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
* doc: create package & update general TOCs * doc: add documentation * add code example * reformat using black
35 lines
714 B
Python
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
|