1

refactor aggregate build process

This commit is contained in:
Christoph
2020-03-09 13:25:38 +01:00
parent 94193d4f50
commit af4a12c892
3 changed files with 17 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import lombok.Getter;
import mops.gruppen2.domain.event.Event;
import java.lang.reflect.Method;
import java.util.List;
/**
* Repräsentiert viele Events als aggregiertes Objekt.
@ -13,12 +14,20 @@ public abstract class Aggregate {
protected long id;
public void apply(List<Event> events) {
events.forEach(this::applyEvent);
}
public void apply(Event event) {
applyEvent(event);
}
/**
* Ruft die spezifische applyEvent-Methode im entsprechenden Aggregat auf.
*
* @param event Event, welches aggregiert wird
*/
public void applyEvent(Event event) {
private void applyEvent(Event event) {
try {
Method method = this.getClass().getDeclaredMethod("applyEvent", event.getClass());
method.setAccessible(true);

View File

@ -18,8 +18,7 @@ public class GroupService {
*/
Group buildGroupFromEvents(List<Event> eventList) {
Group newGroup = new Group();
eventList.forEach(newGroup::applyEvent);
newGroup.apply(eventList);
return newGroup;
}