Comments (10)
Logic层使用了这个抽象的interface,应该有它的所有权,放Logic层,而repo只是实现这个interface的细节。
另外这个MVC分层的术语也太多了吧,Repo/Dao/Protocol/Logic/Controller/Model...
from blog_comment.
- 没错,应该在 logic 里
- 工程领域发声的人比较多,比如 martin fowler,uncle bob 和 ddd 社区里的一堆人,相似的概念他们造了很多不一样的词
Repo 和 Dao(这两个的细微差别在 IDDD 一书里有说明,但实际编码的时候大多数公司都是乱用的)
Protocol 要是单独一层,一般是为了把入口出口协议从业务代码里独立出来,比如我们这里的模块可以同时支持 thrift 和 http 的同一个入口,既然同一个接口要支持两种协议,就必然需要把这种协议适配专门做一层,适配后以统一的 struct 向下传
model 其实用的也比较乱,有的项目 model 层就是一堆 struct(这种情况下,如果这些 struct 是用来和外部交互,可能又被叫 dto 了),而有的项目则认为 model 是“领域模型”,那其实就是 logic。
logic 本身在有的框架/项目里又会叫 service、或者叫什么 business rules
名词确实比较乱,重点理解**
from blog_comment.
- 没错,应该在 logic 里
- 工程领域发声的人比较多,比如 martin fowler,uncle bob 和 ddd 社区里的一堆人,相似的概念他们造了很多不一样的词
Repo 和 Dao(这两个的细微差别在 IDDD 一书里有说明,但实际编码的时候大多数公司都是乱用的)
Protocol 要是单独一层,一般是为了把入口出口协议从业务代码里独立出来,比如我们这里的模块可以同时支持 thrift 和 http 的同一个入口,既然同一个接口要支持两种协议,就必然需要把这种协议适配专门做一层,适配后以统一的 struct 向下传
model 其实用的也比较乱,有的项目 model 层就是一堆 struct(这种情况下,如果这些 struct 是用来和外部交互,可能又被叫 dto 了),而有的项目则认为 model 是“领域模型”,那其实就是 logic。
logic 本身在有的框架/项目里又会叫 service、或者叫什么 business rules名词确实比较乱,重点理解**
理解。
我只是吐槽,我自己内部就把model干掉了,这个名词太容易误导了,我这边没有多协议的情况,所谓protocol层基本上就是protobuf文件了。我的一点感受就是protobuf生成的interface更像是一个更高层次的business rule
from blog_comment.
工程化的东西,有时比较难推动。做PHPer开发时,受Laravel启发比较大,都是由抽象的Contract/Interface,实现具象的类。写Golang时,也秉承了这个习惯。不过很多人并不认可,首先他们觉得可读性较差(不愿意深入追代码的人占大多数),遵循起来挺麻烦,本来几十行代码的事,非要整那么多类(结构体)出来,归根结底,磨刀不误砍柴工,技术债务只会迟到,从来不会缺席。确实如你所说,首先,写单测时,mock很容易;大项目重构时,所有的具象实现类(结构体)只要按约定实现对方方法,基本无缝替换。
from blog_comment.
- 感觉你对贵司”年久失修“的系统很有成见
- 依赖反转得用到刀刃上,不然IDE跳不进去更痛苦
- 你最后一个问题,我觉得遵循一个原则:谁使用抽象,就该谁定义接口
from blog_comment.
@caibirdme ,上班时间摸鱼,要告诉你老板哦
from blog_comment.
@cch123 摸鱼的时候看见你老板了,你说巧不巧
from blog_comment.
@caibirdme orz
from blog_comment.
所见略同,至少 mock 很方便。所以可以得出,不抽 interface 的基本不做单元测
from blog_comment.
@fxmumu ,还有 monkey patch 这种东西,不一定都得 interface 的哦
from blog_comment.
Related Issues (20)
- 为什么要旗帜鲜明地反对 orm 和 sql builder HOT 25
- memory ballast 和 gc tuner 成为历史 HOT 8
- go-redis 和 redis server 版本错位导致的高延时问题一例 HOT 2
- 为什么大公司讲的效率如此虚伪 HOT 11
- 自动调整 GOGC 优化 GO 的 GC CPU 占用 HOT 3
- aws 上 kafka 服务更新导致断连一例 HOT 4
- 平台到底有什么价值 HOT 9
- 如何在 kv 系统中支持简单的 SQL HOT 2
- 微服务税 HOT 6
- 谈一谈es的优势和限制 HOT 2
- sarama producer hang 又一例 HOT 2
- 下一次工业革命近在眼前了 HOT 13
- 非协作式抢占详解 HOT 1
- 给面试官一点小小的 gpt 震撼 HOT 4
- 中台 2023 HOT 3
- 杂谈 HOT 6
- 关于复杂度的一些想法 HOT 2
- 新加坡保本理财指南 HOT 2
- 一些鬼故事 HOT 10
- 怎样提升研发效率(1) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog_comment.