Skip to content

Instantly share code, notes, and snippets.

@HavenShen
Created May 17, 2018 08:30
Show Gist options
  • Save HavenShen/35893fcd93922641245dedcfd8b6ee9f to your computer and use it in GitHub Desktop.
Save HavenShen/35893fcd93922641245dedcfd8b6ee9f to your computer and use it in GitHub Desktop.
Liskov Substitution Principle (LSP).
<?php
$car = new Car();
$driver = new Driver($car);
$driver->go();
class Driver
{
protected $car;
public function __construct(Car $car)
{
$this->car = $car;
}
public function go()
{
$this->car->drive();
}
}
class Car
{
public function drive()
{
// ...Let's go on an adventure!
}
}
class Tesla extends Car
{
//
}
class Audi extends Car
{
//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment