Skip to content

Instantly share code, notes, and snippets.

@ksmylmz
ksmylmz / observer.php
Last active May 19, 2021 06:05
Observer Design Pattern example
<?php
class HookService
{
public function TrackingHookService()
{
$subscriber1 = new Subscriber("http://listener1.com/listenurl",000);
$subscriber2 = new Subscriber("http://listener2.com/listenurl",999);
@ksmylmz
ksmylmz / strategy.php
Last active May 19, 2021 06:08
Strategy Design Pattern
<?php
////1- Öncelikle ödeme için bir base tanımlayalım
interface IPayment
{
public function pay();
}
//2- Farklı Ödeme tiplerine göre implenetasyonları uygulayalım
class PayWithCard implements IPayment
@ksmylmz
ksmylmz / adapter.php
Last active May 19, 2021 06:26
adapter design pattern
<?php
////Pusedio kodlar
class BusinessLayer
{
public function ManageProduct()
{
////Myslq Server Kullanmak istediğimizde
$productManager = new ProductManager( new MysqlAdapter());
$productManager->getData($query,$params);
@ksmylmz
ksmylmz / facade.php
Last active May 19, 2021 06:11
Facade Design Pattern
<?php
class BusinessLayer
{
public function UserRegister(Request $request)
{
$userManager = new UserManagerFacade();
$userManager->SaveUser($request->user);
}
<?php
function registerOrder($order)
{
try
{
//formu validate edelim
if(!isValidForm()) throw new Exception("Form bilgileri doğrulanamadı", 403);
<?php
function registerOrder($order)
{
//formu validate edelim
if(!isValidForm())
{
return json_encode(["status"=>false, "error"=>"Form bilgileri doğrulanamadı"]])
}
<?php
interface IMessage
{
public function sendMessage();
}
////low Level sınıflarımız
<?php
////low Level sınıflarımız
class Email
{
function sendEmail();
}
class SMS
{
<?php
interface IReadable
{
public function read();
}
interface ICreatable
{
public function create();
}
<?php
interface IUserActions
{
public function create();
public function read();
public function update();
public function delete();
}