Changed aggregate example 4 to declare apply() method type, rather than define abstract method.
-from abc import abstractmethod
from collections import defaultdict
from dataclasses import dataclass
from datetime import datetime, timezone
@@ -48,9 +47,7 @@ class Aggregate:
self.apply(new_event)
self._pending_events.append(new_event)
- @abstractmethod
- def apply(self: TAggregate, event: DomainEvent) -> None:
- """Applies event to aggregate."""
+ apply: singledispatchmethod
def collect_events(self) -> List[DomainEvent]:
events, self._pending_events = self._pending_events, []
