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 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体