一个长课还是很多短课? [英] One long class or many shorter classes?

查看:103
本文介绍了一个长课还是很多短课?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,使用一个具有很多函数的长类有什么性能影响吗?

In PHP, is there any performance impact on using one long class with a lot of functions in it? Or is it advisable to use many small classes and call them separately when needed?

我是OOPS的新手,请忽略问题中的任何蠢语。谢谢。

I am a newbie in OOPS and please ignore any silliness in the question. Thanks.

推荐答案

建议不要在拥有代码之前考虑性能。从可维护性和可理解性的角度来看,当然,较小的类,较小的方法是优越的。 (请参阅单一责任原则

It's advisable not to think about the performance before you have the code. From the maintainability and understandability viewpoint, of course, smaller classes, with smaller methods are superior. (see The Single Responsibility Principle)

当你需要优化时,你真的可以将所有的代码汇编(自动)成一个大文件,并节省一些时间include-s。

When you need to optimize, you really can assemble (automatically) all your code into a single big file, and save some time on include-s.

这篇关于一个长课还是很多短课?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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