dongluo9156 2012-04-30 21:21
浏览 119
已采纳

如果我在php类中有超过一百个数据成员(变量),它会明显变慢吗?

I have a PHP class called Vehicle that manages everything pertaining to cars,motorbikes and trucks. I have over a hundred private variables that is associated with every db field in each of the tables cars,bikes,trucks.

For example: A car has: -Fuel Consumption -Max horsepower -Max torque .. etc.. so i have data members

private $fuel;
private $horsepower;
private $toque;

When I do a database query to find a car by id, i store all the rows inside their corresponding variables.

The car table has about 50 fields, the bikes table has 30 fieldsand the trucks 30 fields. So there is over 110 data members.

Is there a better way to do that?

  • 写回答

3条回答 默认 最新

  • duanlang0025 2012-04-30 21:24
    关注

    Inheritance and polymorphism are your friends! The Car should be one class (with 50 properties), bike - another one (30 properties), truck - another (30 properties). They all should extend the Vehicle base class

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP