Skip to content

Instantly share code, notes, and snippets.

View tkouleris's full-sized avatar
:octocat:
Infinite Refactor

Thodoris Kouleris tkouleris

:octocat:
Infinite Refactor
View GitHub Profile
@tkouleris
tkouleris / Observer.php
Created October 8, 2017 16:11
Observe Pattern Implementation
<?php
/*
Observer Design Pattern - Weather Station Example
*/
abstract class Observer{
public function update(){}
}
abstract class Subject{
@tkouleris
tkouleris / Composite.php
Last active September 17, 2017 15:06
Composite Design Pattern
<?php
abstract class SongComposite{
public function songInfo(){}
}
class Song extends SongComposite{
private $songTitle;
private $songBand;
public function __construct($sTitle, $sBand){
$this->songTitle = $sTitle;
@tkouleris
tkouleris / Iterator.php
Created September 17, 2017 04:18
Iterator Design Pattern
<?php
class IntegerRange implements Iterator{
private $start;
private $end;
private $current;
public function __construct($start, $end){
$this->start = $start;
$this->end = $end;
$this->current = $start;
}
@tkouleris
tkouleris / prototypeDP.php
Last active September 2, 2017 14:36
Example of the Prototype Design Pattern
<?php
abstract class PCgame{
protected $title;
protected $productKey;
protected $medium;
protected $box;
public function setTitle($GameTitle){
@tkouleris
tkouleris / Builder.php
Created June 15, 2017 19:16
Builder Design Pattern
<?php
class Car{
private $doors;
private $seats;
private $color;
public function __construct(){
echo "new Car object\r\n";
}
<?php
interface IDiscount{
function calculateDiscount($bill);
}
class NoDiscount implements IDiscount{
public function calculateDiscount($bill){
<?php
/*
* Facade Design Pattern
* -----------------------
*
* Wiki:The Facade design pattern is often used when a system is very complex or difficult to understand because the system has a large number of
* interdependent classes or its source code is unavailable. This pattern hides the complexities of the larger system and provides a simpler
* interface to the client. It typically involves a single wrapper class which contains a set of members required by client. These members access
* the system on behalf of the facade client and hide the implementation details.
*
@tkouleris
tkouleris / Factory.php
Created December 1, 2016 04:06
Factory Design Pattern example
<?php
/*
*
* Factory Design Pattern
* -----------------------
* Wiki: In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating
* objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory
* method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived
* classes—rather than by calling a constructor.
@tkouleris
tkouleris / ChainOfResponsibility.php
Created November 23, 2016 19:36
Chain of responsibility pattern example
<?php
/*
Chain of Responsibility Pattern - Wiki
---------------------------------------
* In object-oriented design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and * a series of processing objects.[1] Each processing object contains logic that defines the types of command objects that it can
* handle; the rest are passed to the next processing object in the chain. A mechanism also exists for adding new processing bjects * to the end of this chain.In a variation of the standard chain-of-responsibility model, some handlers may act as
* dispatchers,capable of sending commands out in a variety of directions, forming a tree of responsibility. In some cases, this
* can occur recursively, with processing objects calling higher-up processing objects with commands that attempt to solve some
* smaller part of the problem; in this case recursion continues until the command is processed, or the entire tree has been
* explored. An XML interpreter might work in thi
@tkouleris
tkouleris / adapter.php
Created July 28, 2016 07:50
Adapter Design Pattern example
<?php
/*
*
* Adapter Design Pattern
* -----------------------
* Wiki: An adapter helps two incompatible interfaces to work
* together. This is the real world definition for an adapter.
* Interfaces may be incompatible but the inner functionality
* should suit the need. The Adapter design pattern allows
* otherwise incompatible classes to work together by converting