首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

【Go实现】实践GoF的23种设计模式:SOLID原则

一种设计方案是把Mq接口拆分成2个子接口Consumable和Producible,让MemoryMq直接实现Consumable和Producible:  // Consumable 消费接口,从消息队列中消费数据... type Consumable interface {  Consume(topic Topic) (*Message, error)  }  ​  // Producible 生产接口,向消息队列生产消费数据...更好的设计应该是保留Mq抽象接口,让Mq继承自Consumable和Producible,这样的分层设计之后,既能满足ISP,又能让实现符合消息队列的领域模型: 具体实现如下:  // Mq 消息队列接口...,继承了Consumable和Producible,同时又consume和produce两种行为  type Mq interface {  Consumable  Producible  }  ​  ...type MemoryMqInput struct {  topic    mq.Topic  consumer mq.Consumable // 只依赖Consumable  }  ​  type AccessLogSidecar

37350
领券