35. understandable
4 small, composable functions - that do one thing
4 hide complexity
4 good names - variables, functions, namespaces,
classes
4 small public API
4 TDD
4 Value objects
38. class Distance
{
private $km;
private function __construct() {}
public static function fromKm($km)
{
$d = new static;
$d->km = $km;
return $d;
}
public function asKm()
{
return $this->km;
}
}
39. class Time
{
private $seconds;
private function __construct() {}
public static function fromSeconds($seconds)
{
$t = new static;
$t->seconds = $seconds;
return $t;
}
public function inHours()
{
return $this->seconds / 3600;
}
}
40. class Speed
{
private $kmph;
public static function fromDistanceAndTime(Distance $d, Time $t)
{
$s = new static;
$s->kmph = $d->asKm() / $t->inHours();
return $s;
}
public function asMph()
{
return $this->kmph * 1.6093;
}
}
42. adaptable
4 Things change - new business knowledge/rules,
changing technologies
4 small functions/classes/modules
4 throw away code
4 dependency injection
4 be abstract, use interfaces