Last active
August 29, 2015 14:21
-
-
Save breeze4/7361db0d92ecbccf7769 to your computer and use it in GitHub Desktop.
CQRS/Event Sourcing design pattern question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Mode { | |
GROUND, AIR, OCEAN; | |
} | |
// *** GENERIC STYLE *** | |
// 1 command to set the mode | |
public SetModeCommand { | |
private final Mode mode; | |
// constructor, getters, etc | |
} | |
// handler: | |
public handle(SetModeCommand command) { | |
eventBus.publish(new ModeChangedEvent(id, command.getMode())); | |
} | |
// *** MORE SPECIFIC STYLE *** | |
// alternative: | |
// 3 commands, each to set the mode with a hardcoded value | |
public SetGroundModeCommand extends AbstractSetModeCommand { | |
private final Mode mode = GROUND; | |
// constructor, getters, etc | |
} | |
// handler alt 1: | |
public handle(AbstractSetModeCommand command) { | |
switch(command.getMode()) { | |
case: GROUND { | |
eventBus.publish(new ChangedToGroundModeEvent(id)); | |
} | |
} | |
} | |
// handler alt 2: | |
public handle(SetGroundModeCommand command) { | |
eventBus.publish(new ChangedToGroundModeEvent(id)); | |
} | |
public handle(SetAirModeCommand command) { | |
eventBus.publish(new ChangedToAirModeEvent(id)); | |
} | |
public handle(SetOceanModeCommand command) { | |
eventBus.publish(new ChangedToOceanModeEvent(id)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment