One long class or many shorter classes?

后端 未结 6 1076
醉梦人生
醉梦人生 2021-02-19 03:01

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?

6条回答
  •  一向
    一向 (楼主)
    2021-02-19 03:50

    In general, people tend to make classes that are too large and complex -- this is because it's often difficult to see where the cohesion boundaries lie. So when you're starting out and a bit unsure, it's better to err on the side of making them too small: you can always coalesce smaller classes into a larger one... it's often much harder to refactor a large class into several small ones.

提交回复
热议问题