douwen5246 2012-07-19 03:31
浏览 29
已采纳

定义抽象函数时的参数名称

I have some abstract base class that defines abstract functions. For example (barebones),

abstract class My_Foo extends CI_Model {
  $protected a;
  $protected b;
  abstract public printWithExtra($extra);
}

class Bar extends My_Foo {
  public printWithExtra($param) {
    echo $this->a, $this->b, $param;
  }
}

Does it matter what I name the parameter when implementing the abstract function? I don't believe it should, but I'm feeling a bit paranoid.

  • 写回答

1条回答 默认 最新

  • dtxob80644 2012-07-19 09:36
    关注

    As far as my knowledge goes, it does not matter what you name the parameter within the function.

    Whether you name it $param or $data or $value, it does not matter since the variable is only available withing the function and not within the class or global scope. however it is always good practice to copy the same naming as the abstract class. It will make your application more readable over time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序