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

别什么都是 继承 #7

Open
aikin opened this issue Jun 22, 2019 · 1 comment
Open

别什么都是 继承 #7

aikin opened this issue Jun 22, 2019 · 1 comment

Comments

@aikin
Copy link
Owner

aikin commented Jun 22, 2019

滥用继承,那都是因为你懒。

@aikin aikin changed the title 别什么都是 *继承*? 别什么都是 *继承* ! Jun 22, 2019
@aikin aikin changed the title 别什么都是 *继承* ! 别什么都是 继承 Jun 22, 2019
@aikin
Copy link
Owner Author

aikin commented Jun 22, 2019

类名要简单,易懂。子类名有两重职责,不仅要描述这些类像什么,还要说明它们之间的区别是什么。类名,为了让代码可以更好的和人沟通,而不是计算机沟通。

继承虽然可以减少代码量,会比原封不动地把超类的内容复制粘贴到所有子类精简得多。和所有减少代码量的技巧一样,它会让代码变得更难读懂;*因为必须理解超类的上下文,然后才能有可能理解子类。*

每一次的增加间接层,都会增加理解的成本。因为需要了解这层抽象,才能知道如何完成下一个具象。

减少类的数量是对系统的改进,只要剩下的类不因此而变得臃肿就好。

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