Skip to content

Instantly share code, notes, and snippets.

View nahidulhasan's full-sized avatar

Nahidul Hasan nahidulhasan

  • Brain Station 23 Ltd.
  • Dhaka,Bangladesh
View GitHub Profile
@nahidulhasan
nahidulhasan / Observer.php
Created July 13, 2016 08:41
Design Pattern
<?php
/*
* Defines a one-to-many dependency between objects so that
* when one object changes state, all its dependents are notified and updated automatically.
*/
interface Subject{
public function attach($observable);
public function detach($index);
<?php
class LogToDatabase
{
public function execute($message)
{
var_dump('log the message to a database :'.$message);
}
}
@nahidulhasan
nahidulhasan / Tea.php
Last active September 27, 2021 15:32
<?php
class Tea
{
public function addTea()
{
var_dump('Add proper amount of tea');
return $this;
}
<?php
class Coffee
{
public function addCoffee()
{
var_dump('Add proper amount of coffee');
return $this;
}
<?php
interface Logger
{
public function execute();
}
<?php
interface Logger
{
public function execute($message);
}
class LogToDatabase implements Logger
{
public function execute($message){
<?php
abstract class Template
{
public function make()
{
return $this
->addHotWater()
->addSugar()
->addPrimaryToppings()
<?php
abstract class AbstractClass
{
// Force Extending class to define this method
abstract protected function getValue();
public function printOut()
{
print $this->getValue() . "\n";
<?php
namespace Demo;
use DB;
class OrdersReport
{
public function getOrdersInfo($startDate, $endDate)
{
$orders = $this->queryDBForOrders($startDate, $endDate);
<?php
namespace Report;
use Report\Repositories\OrdersRepository;
class OrdersReport
{
protected $repo;
protected $formatter;
public function __construct(OrdersRepository $repo, OrdersOutPutInterface $formatter)