在一个类中,可以编写多少个方法?有限制.. [英] In a class, how many methods can be written? is there a limit..

查看:157
本文介绍了在一个类中,可以编写多少个方法?有限制..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个班级中,可以编写多少种方法?是否有限制..

推荐答案

根据经验,一旦你的方法列表不再适合屏幕,它就太多了!如果您无法再轻松记住类的功能,那么OO的全部概念,代码可重用性和关注点分离都会破坏。或者换句话说:如果你的类有很多方法,那么它的设计可能很糟糕,而且应该重构。
As a rule of thumb, once your list of methods no longer fits on the screen, it's too much! The whole concepts of OO, code reusability and separation of concerns break down if you can no longer easily memorize the functionality of a class. Or to put it differently: if your class has that many methods, it's design is probably bad, and it should be refactored.


虽然可能没有技术限制,但是有一些由良好编码/设计实践设定的限制(但不能给出确切的数字)。

什么是课程?提示:例如关注点分离。

当一个类有很多方法时,它会关注太多不同的事物。因此设计错误。
Though there might be no technical limit, there is some kind of limit set by Good Coding/Design Practises (but no exact number can be given).
What is a class about? Hint: E.g. "Separation of concerns".
When a class has many methods, it cares for too many different things. And thus it is wrongly designed.


没有限制,

您可以编写n个方法
No there Is no limit,
You can write n numbers of methods


这篇关于在一个类中,可以编写多少个方法?有限制..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆