Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: abstract backend process logic to service interface #54

Merged
merged 1 commit into from
Jun 4, 2022

Conversation

alimy
Copy link
Collaborator

@alimy alimy commented Jun 3, 2022

  • make abstract backend process logic to service interface

这个PR解决什么问题?
pr主要是把后端的数据处理逻辑接口化、服务化,定义好需要的数据处理逻辑接口,按需要的场景实现对应的服务接口,然后通过统一的函数导出接口服务。

为什么要把后端数据处理逻辑服务接口化?

  1. 方便集成测试、模糊测试; 处理逻辑接口化后,编写测试用例时,可以专门针对测试用例实现服务接口,完成对应的功能测试,当然目前还没怎么写测试用例,但是后续应该会跟上这部分工作。
  2. 方便服务扩展。例如:图片存储服务,目前用的是阿里的AliOSS,如果需要使用其他的对象存储服务,比如腾讯云、华为云的对象存储服务或者自己搭建的MINIO等,只要实现一个定义好的存储服务接口(其内部实现适配对应的底层对象存储服务),就可以在程序启动时就可以根据配置按需去实例化相应的存储服务。
  3. 为功能扩展做准备,比如图片存储支持腾讯云、MINIO等。

后端数据处理逻辑服务接口化的优缺点?
优点: 接口清晰、可扩展性好;
缺点: 代码编写有点繁琐,需要定义接口、编写实现、导出服务等。
总的来说,面向接口编程还是一种比较好的编程范式。

@alimy alimy requested a review from rocboss June 3, 2022 23:05
WalletService
SearchService
StorageService

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议这里可以再抽象解耦一下,比如 PostService, CommentService, UserService

}

// SearchService search service interface that implement base zinc
type SearchService interface {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchSearvice 这个能否再抽象一些,目前的接口基本还是比较耦合Zinc的

@rocboss rocboss merged commit 804bb50 into rocboss:main Jun 4, 2022
@rocboss
Copy link
Owner

rocboss commented Jun 4, 2022

整体想法挺好的,有些接口细节建议还可以进一步解耦,因为本身属于一个CURD的业务系统,如果解耦不当,反而会容易出现过渡设计的情形,先Merge一版

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants