Skip to content

Instantly share code, notes, and snippets.

@nahidulhasan
Last active September 27, 2021 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nahidulhasan/c22a15f8bb9fb3cc90aced789f173b02 to your computer and use it in GitHub Desktop.
Save nahidulhasan/c22a15f8bb9fb3cc90aced789f173b02 to your computer and use it in GitHub Desktop.
<?php
abstract class Template
{
public function make()
{
return $this
->addHotWater()
->addSugar()
->addPrimaryToppings()
->addMilk();
}
protected function addHotWater()
{
var_dump('Pour Hot water into cup');
return $this;
}
protected function addSugar()
{
var_dump('Add proper amount of sugar');
return $this;
}
protected function addMilk()
{
var_dump('Add proper amount of Milk');
return $this;
}
protected abstract function addPrimaryToppings();
}
class Tea extends Template
{
public function addPrimaryToppings()
{
var_dump('Add proper amount of tea');
return $this;
}
}
$tea = new Tea();
$tea->make();
class Coffee extends Template
{
public function addPrimaryToppings()
{
var_dump('Add proper amount of Coffee');
return $this;
}
}
$coffee = new Coffee();
$coffee->make();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment