dqsw7529 2016-03-24 10:31
浏览 29

通过params或直接在方法体中获得params

For example:

Case 1: Passing parameters through method

protected function _arrange_data($data, $sort) { ... }

Case 2: Get parameters in the method body

$this->_set_datas($data);
$this->_set_sort($sort);

protected function _arrange_data() {
    $datas = $this->_get_datas();
    $sort  = $this->_get_sort();
}

Case 1: It look a little messy when a method need 4, 5 parameters. You need to get necessary data before call the method

Case 2: It look more clearly and no need to do anythings before call the method because method will get parameters itself. But I think this case will break "Dependency Injection" principle because it's not loose coupling and hard to maintenance

Question: Which solution do you prefer? Or if you have another way, please tell me. I am all ears.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料