Answer the question
In order to leave comments, you need to log in
What is the best way to organize a domain event using a simple example?
Hello.
Practicing OOP with a DDD approach using a simple example. Let's say we have a faucet in the garden for watering the beds. Let's try to simulate its work. So the faucet can be opened and closed. Let's have a Tap aggregate
class Tap {
// ... id и другие свойства опущены
public function open() { // Emit TapOpened event }
public function close() { // Emit TapClosed event }
}
class TapOpened extends DomainEvent {
// tapId и другие свойства
}
class TapClosed extends DomainEvent {
// tapId и другие свойства
}
interface TimerService {
public function windUp(period): TimerIdentity;
}
class TimerCreated extends DomainEvent {
// timerId и другие свойства
}
class TimerTimeout extends DomainEvent {
// timerId и другие свойства
}
class TapAutoCloser {
private timeService;
public function openTapFor(tap, period) {
tap.open();
timer = timeService->windUp(period);
//...
}
public function timeoutHandler(timerTimeoutEvent) {
// ..
tap.close()
// ..
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question