Skip to content

Commit 581e5f4

Browse files
♻️ refactor: aggregates' methods renamed to decide and evolve
1 parent de1cf40 commit 581e5f4

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/main/java/com/dddheroes/heroesofddd/armies/write/Army.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Army {
3131

3232
@CommandHandler
3333
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING) // performance downside in comparison to constructor
34-
void handle(AddCreatureToArmy command) {
34+
void decide(AddCreatureToArmy command) {
3535
new CanHaveMax7CreatureStacksInArmy(command.creatureId(), creatureStacks).verify();
3636

3737
apply(
@@ -44,13 +44,13 @@ void handle(AddCreatureToArmy command) {
4444
}
4545

4646
@EventSourcingHandler
47-
void on(CreatureAddedToArmy event) {
47+
void evolve(CreatureAddedToArmy event) {
4848
this.armyId = new ArmyId(event.armyId());
4949
creatureStacks.merge(new CreatureId(event.creatureId()), new Amount(event.quantity()), Amount::plus);
5050
}
5151

5252
@CommandHandler
53-
void handle(RemoveCreatureFromArmy command) {
53+
void decide(RemoveCreatureFromArmy command) {
5454
new CanRemoveOnlyPresentCreatures(command.creatureId(), command.quantity(), creatureStacks).verify();
5555

5656
apply(
@@ -63,7 +63,7 @@ void handle(RemoveCreatureFromArmy command) {
6363
}
6464

6565
@EventSourcingHandler
66-
void on(CreatureRemovedFromArmy event) {
66+
void evolve(CreatureRemovedFromArmy event) {
6767
var creatureId = new CreatureId(event.creatureId());
6868
var currentQuantity = creatureStacks.get(creatureId);
6969
var removedQuantity = new Amount(event.quantity());

src/main/java/com/dddheroes/heroesofddd/calendar/write/Calendar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Calendar {
2727
@CommandHandler
2828
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
2929
// performance downside in comparison to constructor
30-
void handle(StartDay command) {
30+
void decide(StartDay command) {
3131
new CannotSkipDays(command, currentMonth, currentWeek, currentDay).verify();
3232

3333
apply(
@@ -41,15 +41,15 @@ void handle(StartDay command) {
4141
}
4242

4343
@EventSourcingHandler
44-
void on(DayStarted event) {
44+
void evolve(DayStarted event) {
4545
calendarId = new CalendarId(event.calendarId());
4646
currentMonth = new Month(event.month());
4747
currentWeek = new Week(event.week());
4848
currentDay = new Day(event.day());
4949
}
5050

5151
@CommandHandler
52-
void handle(FinishDay command) {
52+
void decide(FinishDay command) {
5353
new CanOnlyFinishCurrentDay(command, currentMonth, currentWeek, currentDay).verify();
5454

5555
apply(

src/main/java/com/dddheroes/heroesofddd/creaturerecruitment/write/Dwelling.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Dwelling {
3333

3434
@CommandHandler
3535
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING) // performance downside in comparison to constructor
36-
void handle(BuildDwelling command) {
36+
void decide(BuildDwelling command) {
3737
new OnlyNotBuiltBuildingCanBeBuild(dwellingId).verify();
3838

3939
apply(
@@ -46,15 +46,15 @@ void handle(BuildDwelling command) {
4646
}
4747

4848
@EventSourcingHandler
49-
void on(DwellingBuilt event) {
49+
void evolve(DwellingBuilt event) {
5050
this.dwellingId = new DwellingId(event.dwellingId());
5151
this.creatureId = new CreatureId(event.creatureId());
5252
this.costPerTroop = Cost.fromRaw(event.costPerTroop());
5353
this.availableCreatures = Amount.zero();
5454
}
5555

5656
@CommandHandler
57-
void handle(IncreaseAvailableCreatures command) {
57+
void decide(IncreaseAvailableCreatures command) {
5858
new OnlyBuiltDwellingCanHaveAvailableCreatures(dwellingId).verify();
5959
// todo: check creatureId for the dwelling!
6060

@@ -68,13 +68,13 @@ void handle(IncreaseAvailableCreatures command) {
6868
}
6969

7070
@EventSourcingHandler
71-
void on(AvailableCreaturesChanged event) {
71+
void evolve(AvailableCreaturesChanged event) {
7272
this.availableCreatures = new Amount(event.changedTo());
7373
}
7474

7575
@CommandHandler
7676
// @CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
77-
void handle(RecruitCreature command) {
77+
void decide(RecruitCreature command) {
7878
// if(dwellingId == null){
7979
// throw new DomainRule.ViolatedException("Only not built building can be build");
8080
// }
@@ -97,7 +97,7 @@ void handle(RecruitCreature command) {
9797
}
9898

9999
@EventSourcingHandler
100-
void on(CreatureRecruited event) {
100+
void evolve(CreatureRecruited event) {
101101
// todo: consider if it's OK or RecruitCreature should cause also AvailableCreaturesChanged event
102102
this.availableCreatures = this.availableCreatures.minus(new Amount(event.quantity()));
103103
}

0 commit comments

Comments
 (0)