Created
September 24, 2013 09:27
-
-
Save ertuncefeoglu/6682424 to your computer and use it in GitHub Desktop.
Fluent interface design patter için PHP ile örnek
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
fluent interface design pattern - method chaining olarak da adlandırılabilir | |
class propertylere değer atayan setter methodlar içersinde return $this ile objeji döndürüyoruz | |
public function setAd($ad){ | |
$this->_ad = $ad; | |
} | |
public function setSoyad($soyad){ | |
$this->_soyad = $soyad; | |
} | |
yerine | |
public function setAd($ad){ | |
$this->_ad = $ad; | |
return $this; | |
} | |
public function setSoyad($soyad){ | |
$this->_soyad = $soyad; | |
return $this; | |
} | |
böylece | |
$ornek = new Ogrenci; | |
$ornek->setAd('Bilal'); | |
$ornek->setSoyad('Baraz'); | |
echo $ornek->getOgrenci(); | |
yerine | |
$ornek = new Ogrenci; | |
$ornek->setAd('Bilal')->setSoyad('Baraz')->setDogum('1993'); | |
echo $ornek->getOgrenci(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment