我在读有关对象健美操和规则之一是wrapping primitive types and strings:包装原始类型的优点?
class UIComponent {
public function repaint($animate = true)
{
//
}
}
$component->animate(false);
变为:
class UIComponent {
public function repaint(Animate $animate)
{
//
}
}
class Animate {
private $animate;
public function __construct($animate = true)
{
$this->animate = $animate;
}
}
$component->animate(new Animate(false));
我得到什么好处这种技术?在我看来,我认为这只是复杂的东西,并增加了更多的代码行。