SlideShare une entreprise Scribd logo
1  sur  25
Design Patterns
as power of programming
Lukas Lesniewski
About me
PHP Programmer
Experience with Zend
Framework 1 and 2
Speaker at Joomla! Day
2013 Poland
Power of Open Source:
PHP
PHP
24%
PHP as language
Java PHP Python
Ruby .NET Perl
ASP
PHP
75%
Servers usage
Java PHP
Python Ruby
.NET Perl
ColdFusion
PHP Frameworks
Zend
CakePHP
Symfony
YiiWACT
Prado
Akelos
CodeIgniter
Joomla
Wordpress
Laravel
Phalcon
…and more!
Framework’s features
Inversion controll
Default Behavior
Extensibility
Non-moditiable
Close & Open
plugin2
plugin3
plugin1
Shop
tekst
How to use it?
Time to learn patterns!
Singleton
Programmer
Singleton
class SimpleSingleton {
private static $_instance = null;
private function __constructor() {}
public static function getInstance() {
if (!static::$_instance)
static::$_instance = new SimpleSingleton();
return static::$_instance;
}
}
// $bad = new SimpleSingleton();
$good = SimpleSingleton::getInstance();
JApplicationCms
Registry
class MyRegistry {
private static $_data = array();
public static function setItem($key, $value) {
static::$_data[$key] = $value;
}
public static function getItem($key) {
return static::$_data[$key];
}
public static function hasItem($key) {
return array_key_exists($key, static::$_data);
}
public static function getItems() {
return static::$_data;
}
}
Register::setItem("key1", new stdClass);
Register::setItem("key2", 2);
JRegistry
Dependency injectionProgrammer Interface
Interface
Interface
Interface
Interface
DI
interface ComputerInterface {
public function start();
public function shutdown();
public function hideMyFavoritesVideosFolder();
public function cleanBrowserHistory();
public function getJoomla();
}
class LinuxComputer implements ComputerInterface {…}
class MacComputer implements ComputerInterface {…}
class WinComputer implements ComputerInterface {…}
Container
DI
class Programmer {
private $computer;
public function setComputer(ComputerInterface $c) {
$this->computer = $c;
}
public function __construct(ComputerInterface $c) {
$this->setComputer($c);
}
public function code() {
if ($this->computer->getJoomla() == NULL) {
throw new Exception('Impossible!', 1);
}
return 'You're so lucky!';
}
}
$c = new LinuxComputer();
$p = new Programmer($c);
$p->code();
Container
Factory
abstract class Programmer {
abstract public function code();
private $computer;
public function setComputer(ComputerInterface $c) {
$this->computer = $c;
}
}
class JavaProgrammer extends Programmer {
public function code() {
echo 'I use Java 8 on my' . $this->computer;
}
}
class PHPProgrammer extends Programmer {
public function code() {
echo 'I use Joomla on my' . $this->computer;
}
}
class CPPProgrammer extends Programmer {
public function code() {
echo 'I use c++ on my' . $this->computer;
}
}
JFractory
Factory
class ProgrammerFactory {
public static function createProgrammer($lang, $computer) {
$p;
switch ($lang) {
case 'JAVA':
$p = new JavaProgrammer();
break;
case 'PHP':
$p = new PHPProgrammer();
break;
case 'C++':
$p = new CPPProgrammer();
break;
default:
$p = new PHPProgrammer();
break;
}
switch ($computer) {
default:
$p->setComputer(new LinuxComputer);
break;
}
return $p;
}
}
JFractory
JoomlaSiteWithMyPlugin
WpSiteWithMyPlugin
DrupalSiteWithMyPlugin
JoomlaSiteWithTemplate
JoomlaSite
DrupalSiteWithTemplate
WpSiteDrupalSite
WpSiteWithTemplate
Site
Template
getPrice()
Plugin
getPrice()
DecoratorJoomlaSite
getPrice()
Decorator
abstract class Site {
abstract public function getPrice();
private $desc = "There is no description";
public function getDesc() {
return $desc;
}
}
class WordpressSite extends Site {
private $desc = "This is a Wordpress site";
public function getPrice() {
return 99;
}
}
class JoomlaSite extends Site {
private $desc = "This is a Joomla Site";
public function getPrice() {
return 99;
}
}
class DrupalSite extends Site {
private $desc = "This is a Drupal Site";
public function getPrice() {
return 99;
}
}
Decorator
class AmazingTemplate extends Site {
private $site;
public function __construct (Site $site) {
$this->site = $site;
}
public function getPrice() {
return $this->site->getPrice() + 199;
}
}
class MyPlugin extends Site {
private $site;
public function __construct (Site $site) {
$this->site = $site;
}
public function getPrice() {
return $this->site->getPrice() + 49;
}
}
$site = new JoomlaSite();
$site = new AmazingTemplate($site);
$site = new MyPlugin($site);
$site = new MyPlugin($site);
Template
return 199
Plugin
return 49
JoomlaSite
return 99
–Steve Jobs
„When you first start off trying to solve a problem,
the first solutions you come up with are very
complex, and most people stop there. But if you
keep going, and live with the problem and peel
more layers of the onion off, you can often times
arrive at some very elegant and simple
solutions.”
facebook.com/LLUKAS.DE
Sources
http://en.wikipedia.org/wiki/Software_framework
http://blog.websitesframeworks.com/2013/03/program
ming-language-statistics-in-server-side-161/
http://langpop.com/

Contenu connexe

Tendances

Php(report)
Php(report)Php(report)
Php(report)
Yhannah
 
Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事
yangdj
 
Perl In The Command Line
Perl In The Command LinePerl In The Command Line
Perl In The Command Line
Marcos Rebelo
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
alexjones89
 

Tendances (20)

Php(report)
Php(report)Php(report)
Php(report)
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Any event intro
Any event introAny event intro
Any event intro
 
Zeppelin Helium: Spell
Zeppelin Helium: SpellZeppelin Helium: Spell
Zeppelin Helium: Spell
 
Perlbal Tutorial
Perlbal TutorialPerlbal Tutorial
Perlbal Tutorial
 
Anyevent
AnyeventAnyevent
Anyevent
 
Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事Adobe董龙飞:关于PhoneGap的12件事
Adobe董龙飞:关于PhoneGap的12件事
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Xdebug - Your first, last, and best option for troubleshooting PHP code
Xdebug - Your first, last, and best option for troubleshooting PHP codeXdebug - Your first, last, and best option for troubleshooting PHP code
Xdebug - Your first, last, and best option for troubleshooting PHP code
 
PHP - Introduction to PHP Error Handling
PHP -  Introduction to PHP Error HandlingPHP -  Introduction to PHP Error Handling
PHP - Introduction to PHP Error Handling
 
Perl In The Command Line
Perl In The Command LinePerl In The Command Line
Perl In The Command Line
 
Perl web app 테스트전략
Perl web app 테스트전략Perl web app 테스트전략
Perl web app 테스트전략
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
Php Debugger
Php DebuggerPhp Debugger
Php Debugger
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Automated code audits
Automated code auditsAutomated code audits
Automated code audits
 
ActionHeroJS Talk
ActionHeroJS TalkActionHeroJS Talk
ActionHeroJS Talk
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
Low Latency Logging with RabbitMQ (PHP London - 4th Sep 2014)
 

Similaire à Design patterns as power of programing

Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
wilburlo
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
Fabien Potencier
 

Similaire à Design patterns as power of programing (20)

Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Dependency Injection Smells
Dependency Injection SmellsDependency Injection Smells
Dependency Injection Smells
 
PHP and COM
PHP and COMPHP and COM
PHP and COM
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Laravel level 0 (introduction)
Laravel level 0 (introduction)Laravel level 0 (introduction)
Laravel level 0 (introduction)
 
Clear php reference
Clear php referenceClear php reference
Clear php reference
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Phone gap 12 things you should know
Phone gap 12 things you should knowPhone gap 12 things you should know
Phone gap 12 things you should know
 

Plus de Lukas Lesniewski

Plus de Lukas Lesniewski (7)

Budowa usług internetowych: SOAP, Websockets
Budowa usług internetowych: SOAP, WebsocketsBudowa usług internetowych: SOAP, Websockets
Budowa usług internetowych: SOAP, Websockets
 
Wstęp do projektowania usług internetowych: część 1 - rest
Wstęp do projektowania usług internetowych: część 1 - restWstęp do projektowania usług internetowych: część 1 - rest
Wstęp do projektowania usług internetowych: część 1 - rest
 
Piszemy sklep java
Piszemy sklep javaPiszemy sklep java
Piszemy sklep java
 
Joomla Day Poland 15 - Docker
Joomla Day Poland 15 - DockerJoomla Day Poland 15 - Docker
Joomla Day Poland 15 - Docker
 
Automatyzacja pracy w zespole: efekt synergii
Automatyzacja pracy w zespole: efekt synergiiAutomatyzacja pracy w zespole: efekt synergii
Automatyzacja pracy w zespole: efekt synergii
 
Agile i Scrum: projekty z klasą (JUG Olsztyn 2015)
Agile i Scrum: projekty z klasą (JUG Olsztyn 2015)Agile i Scrum: projekty z klasą (JUG Olsztyn 2015)
Agile i Scrum: projekty z klasą (JUG Olsztyn 2015)
 
Joomla w świecie korporacji: JDay Poland 2014
Joomla w świecie korporacji: JDay Poland 2014Joomla w świecie korporacji: JDay Poland 2014
Joomla w świecie korporacji: JDay Poland 2014
 

Dernier

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Dernier (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 

Design patterns as power of programing