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

函数只做一件事 #3

Open
aikin opened this issue Apr 26, 2019 · 0 comments
Open

函数只做一件事 #3

aikin opened this issue Apr 26, 2019 · 0 comments

Comments

@aikin
Copy link
Owner

aikin commented Apr 26, 2019

怎么定义一件事?我觉得就像是问,微服务拆分,多小才算小。我觉得没有标准。但是有一些原则参考:
简单的原则,提取到不能提取为止。当然提取的过程不只是为了 extract method,然后命个函数名字而已,而更应该关注的是抽象。保证函数中的代码处于一个抽象层级,将其它的细节实现就提取出去。

举个栗子:用户注册,同一层次的抽象就是:验证 -> 加密 -> 存储 ,具体怎么验证 、怎么加密、怎么存储的实现细节用其它的函数完成,或者说其它的类完成。不应该在都在注册的函数内。

我理解核心思想是为了提高可读性和可维护性。

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

No branches or pull requests

1 participant