Skip to content

Instantly share code, notes, and snippets.

@ertuncefeoglu
Created September 24, 2013 09:27
Show Gist options
  • Save ertuncefeoglu/6682424 to your computer and use it in GitHub Desktop.
Save ertuncefeoglu/6682424 to your computer and use it in GitHub Desktop.
Fluent interface design patter için PHP ile örnek
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