Created
November 15, 2019 13:00
-
-
Save paveljanda/cba6d31be920217c620289e54fed7c1c to your computer and use it in GitHub Desktop.
Current Type variance changes breaks the Liskov substitution principle
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 | |
interface FuelType | |
{ | |
} | |
class Gas implements FuelType | |
{ | |
public function burn(int $litres) {} | |
}; | |
class Battery implements FuelType | |
{ | |
public function discharge(int $kWh) {} | |
}; | |
class Vehicle | |
{ | |
public function drive(Gas $fuel) | |
{ | |
$battery->burn(10); | |
} | |
} | |
class ElectricVehicle extends Vehicle | |
{ | |
public function drive(FuelType $battery) | |
{ | |
// do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment