One long class or many shorter classes?

后端 未结 6 1077
醉梦人生
醉梦人生 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 04:01

    Personally for me I would much prefer to break the classes down into smaller files based on what they are for. If that's business objects then having a 'customer.class.php' 'account.class.php' etc would be my preference.

    In most of the projects on which I've worked it's been like this, then a larger 'lib' or 'common' file which includes lots of various functions which are used all over the place.

提交回复
热议问题