Skip to content

Instantly share code, notes, and snippets.

@adililhan
Created October 9, 2012 21:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adililhan/3861544 to your computer and use it in GitHub Desktop.
Save adililhan/3861544 to your computer and use it in GitHub Desktop.
PHP'de polimorfizm örneği
<?php
interface Telefon{
function TelefonEt($TelNo);
}
class CepTelefonu implements Telefon{
private $kontorVarMi = true;
private $operatorUygunMu = false;
function TelefonEt($TelNo){
if($this->kontorVarMi){
if($this->operatorUygunMu)
return $TelNo . " aranıyor...\n";
else
return "Hatlar yoğun sonra ara.\n";
}
else
return "Kontörünüz yok";
}
}
class JetonluTelefon implements Telefon{
private $jetonVarMi = false;
function TelefonEt($TelNo){
if($this->jetonVarMi)
return $TelNo . " aranıyor...\n";
else
return "Jetonunuz yok\n";
}
}
class EvTelefonu implements Telefon {
private $faturaYatirildiMi = true;
function TelefonEt($TelNo){
if($this->faturaYatirildiMi)
return $TelNo . " aranıyor...\n";
else
return "Faturayı yatırmamışsın. Bir yeri arıyamazsın\n";
}
}
$cep = new CepTelefonu;
$jeton = new JetonluTelefon;
$ev = new EvTelefonu;
echo $cep->TelefonEt("+90 123 45 67");
echo $jeton->TelefonEt("0 5123 456 78 90");
echo $ev->TelefonEt("0 312 123 45 67");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment