3

如何对业务代码中进行抽象和提取公有逻辑呢?

 2 years ago
source link: https://www.v2ex.com/t/792566
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

如何对业务代码中进行抽象和提取公有逻辑呢?

  zstone123 · 2 天前 · 1700 次点击
之前写的代码可能比较随意,没有考虑过这个问题。现在遇到的问题是两个接口代码相似度可能超过 80%。
1.对相同的代码封装为函数,不同的代码用接口去实现。(只是这么一个想法,但具体没啥实现思路
2.将两个接口合为一个接口。这样的问题是可能会多了许多 if/else 。
真心向各位请教一下,有什么比较好的做法。

第 1 条附言  ·  1 天前

感谢各位的回答,感觉对我来说很有帮助。
总结一下:
1.去看开源代码,看好的设计。
2.对代码场景足够了解,先判断是否需要封装、抽象。
3.code 。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK