A class should have one and only one responsibility.
use Illuminate\Support\ServiceProvider; class EventServiceProvider extends ServiceProvider { public function register() { $this->app['events'] = $this->app->share(function($app) { return new Dispatcher($app); }); } }
A class should be open for extension, but closed for modification.
use Stanley\Example\PartInterface; use Illuminate\Support\Collection; public function getTotal(Collection $parts) { return $parts->reduce(function(PartInterface $part) { return $part->getPrice(); }); }
Objects should replaceable with instances of their subtypes.
abstract class Exam { abstract public function score(); } class Quiz extends Exam { public function score() { return "100"; } } class Grade { protected $scores; public function calculate(Exam $exam) { $this->scores += $exam->score(); } }
A client should not be forced to implement methods that it doesn't use.
Abstractions should not depend upon details. Details should depend upon abstractions.