Created
March 29, 2022 20:23
-
-
Save muratcakmaksoftware/8d6a7cd636d205eb865cb4de6a394c11 to your computer and use it in GitHub Desktop.
Liskov Substitution Prenciple
This file contains hidden or 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 | |
//Liskov Substitution Principle | |
interface Wing | |
{ | |
public function flap(); | |
/** | |
* Chicken class'ında tavuk uçamaz bu yüzden fly ayrı bir interface alınmıştır. | |
*/ | |
//public function fly(); | |
} | |
interface FlyingWing | |
{ | |
public function fly(); | |
} | |
class Bird implements Wing,FlyingWing | |
{ | |
public function flap() | |
{ | |
echo 'Bird flapped its wings'; | |
} | |
public function fly() | |
{ | |
echo 'Bird flying'; | |
} | |
} | |
class Chicken implements Wing | |
{ | |
public function flap() | |
{ | |
echo 'Chicken flapped its wings'; | |
} | |
/** | |
* Tavuk uçamaz bu yüzden hata fırlatılır ama bu liskov substitution prenciple uymaz. | |
* Böyle bir durumda uçmak için ayrı bir interface oluşturup implements etmeliyiz. | |
*/ | |
/*public function fly() | |
{ | |
throw new NotImplementedException(); | |
}*/ | |
} | |
$bird = new Bird(); | |
$bird->flap(); | |
echo '<br/>'; | |
$bird->fly(); | |
echo '<br/>'; | |
$chicken = new Chicken(); | |
$chicken->flap(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment