Created
May 17, 2018 08:30
-
-
Save HavenShen/35893fcd93922641245dedcfd8b6ee9f to your computer and use it in GitHub Desktop.
Liskov Substitution Principle (LSP).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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