forked from yangweijie/clean-code-php
-
Notifications
You must be signed in to change notification settings - Fork 160
这里是不是写错了
迷人的小夏 edited this page Dec 9, 2021
·
1 revision
推荐使用 但是是bad
推荐使用 final 类
能用时尽量使用 final 关键字:
阻止不受控的继承链
鼓励 组合.
鼓励 单一职责模式.
鼓励开发者用你的公开方法而非通过继承类获取受保护方法的访问权限.
使得在不破坏使用你的类的应用的情况下修改代码成为可能.
The only condition is that your class should implement an interface and no other public methods are defined.
For more informations you can read the blog post on this topic written by Marco Pivetta (Ocramius).
Bad:
final class Car { private $color;
public function __construct($color)
{
$this->color = $color;
}
/**
* @return string The color of the vehicle
*/
public function getColor()
{
return $this->color;
}
}
Good:
interface Vehicle