I am trying to understand what Configuration Object pattern is. For instance in php, how to write the following class using Configuration Object pattern?
class User extends People {
public function __construct($name , $email){}
}
答案 0 :(得分:1)
赞:
class User extends People {
private $name;
private $email;
public function __construct($conf){
$this->name = $conf->name;
$this->email = $conf->email;
}
}
当然,当您要配置数据库连接或某些API客户端或类似的东西时,此模式适用于更为复杂的情况。当您需要传递许多属性或对它们执行一些操作时,此模式很有用。
我认为这是有关此模式的好文章:https://code.tutsplus.com/tutorials/whats-a-configuration-object-and-why-bother-using-it--active-11580