Skip to content

Instantly share code, notes, and snippets.

@muratcakmaksoftware
muratcakmaksoftware / memento.php
Created May 3, 2022 19:14
Memento Design Pattern
<?php
//Özelliğe ait asıl sınıf
class Originator
{
private $id;
private $name;
public function __construct($id, $name)
{
@muratcakmaksoftware
muratcakmaksoftware / mediator.php
Created May 3, 2022 11:04
Mediator Design Pattern
<?php
interface MediatorInterface
{
public function notify(object $sender, string $event);
}
//Mediator
class ConcreteMediator implements MediatorInterface
{
@muratcakmaksoftware
muratcakmaksoftware / iterator.php
Created May 2, 2022 17:44
Iterator Design Pattern
<?php
interface StackIteratorInterface
{
public function first();
public function next();
public function current();
@muratcakmaksoftware
muratcakmaksoftware / interpreter.php
Created May 1, 2022 16:38
Interpreter Design Pattern
<?php
//İstemci tarafından alınan bilgiyi ve çevirilmiş olan bilgiyi tutar.
class Context
{
public string $input;
public int $total;
}
//RoleExpression. Ne tür bir çevirme işlemleri gerçekleştirilecekse fonksiyonlar belirlenir.
@muratcakmaksoftware
muratcakmaksoftware / command.php
Created May 1, 2022 12:58
Command Design Pattern
<?php
//Command //Yapılabilecek işlevler
interface CommandInterface
{
public function execute();
}
//Command A //Özelliğe ait basit A işlevi
class FeatureACommand implements CommandInterface
@muratcakmaksoftware
muratcakmaksoftware / chain_of_responsibility.php
Created April 29, 2022 21:16
Chain of Responsibility Design Pattern
<?php
/**
* Zinciri yapabilmek için gereklilikler zorunlu değildir yazılması.
*/
interface Handler
{
public function addChain(Handler $handler): Handler; //Handler'la alakalı sınıfları zincire ekleyebilmek için
public function next($request); //sıradaki sınıfı çağırması için
@muratcakmaksoftware
muratcakmaksoftware / flyweight.php
Created April 28, 2022 19:38
Flyweight Design Pattern
<?php
//Flyweight
abstract class FeatureAbstract
{
//Intrinsic - Ortak paylaşılan veriler
protected $pi = 3.14; //Aynı değere sahip veriler aynı yerden çekilir.
protected $year = 2022;
//Extrinsic - sınıfa göre değişkenlik gösteren veriler.
@muratcakmaksoftware
muratcakmaksoftware / decorator.php
Created April 26, 2022 17:08
Decorator Design Pattern
<?php
//Component(Bileşen) - Özellik
interface NotificationInterface
{
public function send();
}
//ConcreteComponent - Özelliğe ait basit sınıf.
class Notification implements NotificationInterface
@muratcakmaksoftware
muratcakmaksoftware / composite.php
Created April 24, 2022 18:07
Composite Design Pattern
<?php
enum Position {
case MANAGER;
case TEAM_LEADER;
case BACKEND_TEAM_LEADER;
case FRONTEND_TEAM_LEADER;
case DEVELOPER;
case TESTER;
case DESIGNER;
@muratcakmaksoftware
muratcakmaksoftware / bridge.php
Created April 23, 2022 18:47
Bridge Design Pattern
<?php
// Özellik 1 //Bridge 1
interface ShapeInterface
{
public function draw();
}
//Dikdortgen sekli //Özellik 1 varsayonu 1 //ImplementationA
class Rectangle implements ShapeInterface