清洁构造方法
我有一个具有大量参数的课程,
class Foo {
public $d1;
public $d2;
public $d3;
...
public function __construct($d1,$d2,$d3,$d4,$d5,$d6)
{
$this->d1 = $bar->d1;
$this->d2 = $bar->d2;
...
}
}
我想在方法__构造我的尝试中清洁代码
:
class Bar {
public $d1;
public $d2;
public $d3;
...
}
class Foo {
public $d1;
public $d2;
public $d3;
...
public function __construct(Bar $bar)
{
$this->d1 = $bar->d1;
$this->d2 = $bar->d2;
...
}
}
在这种结构中,我想观察两个重要点:
1-干净的代码
2-每当有人想成为此类的对象时,他都必须根据酒吧类的结构来做
我的结构正确吗?您有更好的报价吗?
I have a class with a large number of parameters in the construct method
class Foo {
public $d1;
public $d2;
public $d3;
...
public function __construct($d1,$d2,$d3,$d4,$d5,$d6)
{
$this->d1 = $bar->d1;
$this->d2 = $bar->d2;
...
}
}
I want to clean the code in method __construct
my try :
class Bar {
public $d1;
public $d2;
public $d3;
...
}
class Foo {
public $d1;
public $d2;
public $d3;
...
public function __construct(Bar $bar)
{
$this->d1 = $bar->d1;
$this->d2 = $bar->d2;
...
}
}
In this structure, I want to observe two important points :
1 - clean code
2 - Whenever someone wants to make an object of this class, he must make it according to the structure of the Bar class
Is my structure correct? Do you have a better offer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论