所以猜想我有这种领域事件:
class BookChangedName...
class BookType1ChangedName extends BookChangedName...
class BookType2ChangedName extends BookChangedName...
是更好还是:
class BookChangedName{
enum bookType = BOOK_TYPE_1;
}
因为他们说只有在类之间存在不同的行为时才使用继承,所以我假设在这里我会使用枚举示例(案例 #2)——因为域事件只是简单的 DTO。
但同样,在我的领域中,这种不同类型的事件具有不同的含义(不同的处理路径)。因此,如果我使用示例#1,我最终会得到很多:
if(event instanceof BookType1ChangedName){
//do smth in domain
}
else if(event instanceof BookType2ChangedName){
//do smth in domain
}
而且我不能像这样明确:
when(BookType1ChangedName event){...
我将不得不进行某种预处理,例如:
@EventHandler(matcher_pattern = event->event.bookType==BOOK_TYPE_1)
when(BookChangedNameevent){...