3. 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
12. 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
13. 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
14.
15. 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
16. 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
19. 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;
}
}
20. 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);
23. –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.”