Skip to content

Instantly share code, notes, and snippets.

@muratcakmaksoftware
Created May 5, 2022 18:27
Show Gist options
  • Save muratcakmaksoftware/d997cdbcf0c33ba90d2eb34f1a46b518 to your computer and use it in GitHub Desktop.
Save muratcakmaksoftware/d997cdbcf0c33ba90d2eb34f1a46b518 to your computer and use it in GitHub Desktop.
Template Method Design Pattern
<?php
//Özelliğin soyut sınıfı algoritmanın adımlarının belirlenmesi gereken sınıftır.
//Ortak metotlar burada yazılır.
abstract class AbstractClass
{
//Algoritmayı çalıştırma.
public function run()
{
$this->work1();
$this->baseWork2();
$this->work2();
$this->baseWork1();
}
//Ortak metotlar
public function baseWork1()
{
echo 'Base work 1';
}
public function baseWork2()
{
echo 'Base work 2';
}
//Değişen iş metotları
public abstract function work1();
public abstract function work2();
}
class ConcreteClassA extends AbstractClass
{
public function work1()
{
echo 'Class A work 1';
}
public function work2()
{
echo 'Class A work 2';
}
}
class ConcreteClassB extends AbstractClass
{
public function work1()
{
echo 'Class B work 1';
}
public function work2()
{
echo 'Class B work 2';
}
}
$classA = new ConcreteClassA();
$classA->run();
//Class A work 1
//Base work 2
//Class A work 2
//Base work 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment