c++ - 在事件溯源模式中,您是否有两个不同的类来读取和写入事件?

标签 c++ domain-driven-design event-sourcing

事件流中事件的存储是否应该与事件流中事件的读取分开实现?

例如,下面的抽象基类提供了一种持久化事件的方法,以便以后可以重播。

class event_store_t {
public:
    virtual void store(const event_t& event) = 0;
    virtual ~event_store_t() {}
};

用于测试的具体派生类的接口(interface)如下:

class ostream_event_store_t : public event_store_t {
public:
    virtual void store(const event_t& event);
};

现在,当稍后重放事件时,是否应该有一个单独的类来读取事件。例如,抽象基类显示为:

class event_stream_t {
public:
    virtual boost::shared_ptr<event_t> read() = 0;
};

具体的派生类显示为:

class istream_event_stream_t : public event_stream_t {
public:
    istream_event_stream_t(std::istream& input) : input_(input) {}
    virtual boost::shared_ptr<event_t> read() {
        // Read the event.
    }
};

最佳答案

Should the storing of events in the event stream be implemented separately from the reading of events in the event stream?

可能不是?

将加载实现与存储实现分开的主要动机是您可以独立交换实现。

如果这还没有发生在你身上,那么你是在预先将成本加载到你的设计中,假设现在分离成本比以后分离成本更有效,请记住在这个假设中“以后”你会比现在更了解变革的要求。

这似乎不是一个好选择。

也就是说,您可能已经注意到需要读取功能的消费者并不总是需要写入功能,反之亦然。因此,拥有一个与写入接口(interface)分开的读取接口(interface),并使用一个模块同时实现这两种接口(interface)可能是有意义的。

关于c++ - 在事件溯源模式中,您是否有两个不同的类来读取和写入事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32652507/

相关文章:

c++ - 创建带有和不带有 new 关键字的 C++ 对象

c++ - "memory corruption"当遵循物理教程 : how to fix? 时

security - 使用 DDD 时将安全性放在哪里 - 领域驱动设计

apache-kafka - 事件溯源适用于批量输入吗?

domain-driven-design - 具有副作用的事件溯源

C++ STL - 检测到达二进制文件的末尾

c++ - 用于 double 和单精度类型的通用对称对 C++

uml - 实体和聚合之间的 UML 区别是什么?

domain-driven-design - DDD/CQRS : where to persist

c# - 聚合根和 child