3 ms·
I'm not sure... sounds like CQRS (though it's a term I don't think I've ever seen before...) is independent. Like, you can have one data structure for read/writ
by to3m 10y ago
I'm not sure... sounds like CQRS (though it's a term I don't think I've ever seen before...) is independent. Like, you can have one data structure for read/write, and you just don't get public access to the write interface directly, only through functions that add to the event list and then do the event. Along the lines of something vaguely like this, perhaps:
void Stuff::AddThing(Thing *thing) {
this->AddEvent(new AddThingEvent(thing));
}
void Stuff::AddEvent(Event *event) {
m_events.push_back(event);
event->Execute(this);
}
void AddThingEvent::Execute(Stuff *stuff) {
stuff->m_things.push_back(m_thing);
}
and maybe AddThingEvent is a friend of Stuff, or it's an inner class, or whatever you like.
Maybe this is what he meant though.
- Terr_ 10y agoI think that most of the time event-sourcing will impact your model/business-logic layer, because you often want to capture the intent of changes, rather than calculating a naive combined delta of all changes that occurred in memory. If so, that means that instead of a CRUD interface like: if(customer.getApprovalLevel() < 5){ customer.setApprovalLevel(5); customer.setApprover(currentUser); } saveChangesSomehow(customer); So you'll end up with an API that's a bit more CQS (no 'R' yet) with: if(customer.getApprovalLevel() < 5){ customer.promoteApprovalLevel(5, currentUser); } saveChangesSomehow(customer); That way you capture each change-event at the right granularity with the necessary data. Finally, CQRS comes into play because you want to do something with that rich event data, such as eagerly populating a table: recentApprovals = getRecentApprovals(); if(recentApprovals.length() > 0){ sendApprovalAuditReport(recentApprovals); }