dongyong1942 2015-03-05 08:13
浏览 22

是否可以使用大类定义?

I like having my Objects very polyvalent. I code functions that I don't even use in the main purpose program, just in case my program get more complex. My classes hence get quickly large in height of lines. But what about the performance ? I have no idea how php treats my files. Let's say i have 30 functions in my class, when an Object is instanciated from that class just for the use of 1 function in it, how is the whole code handled ? is all the logic loaded in the memory ? or does PHP anticipate and only build the used functions and data ?

In other words, is it okay to have very large files ?

  • 写回答

1条回答 默认 最新

  • du8864 2015-03-05 08:17
    关注

    No, PHP doesn't anticipate what parts of a file or class you're going to use before you've used them, how can it know in advance?

    When you load a class the entire class is resident in memory. Of course, code is only loaded once per request; so you only ever have one copy of the class methods in memory at a time, no matter how many object instances you create. However, if you're defining a great many more properties, then those properties are taking up memory on a per-instance basis

    But having large classes with a great many methods that you don't use is generally considered bad practise, and contrary to the principles of SOLID. Large, monolithic classes are harder to maintain than small, more-refined classes that serve very specific purposes

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测