Skip to content

Commit 52edf26

Browse files
committed
Hollywood Principle Implemented.
1 parent 51664ae commit 52edf26

File tree

11 files changed

+124
-0
lines changed

11 files changed

+124
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
//Client.php
3+
function __autoload($class_name) {
4+
include $class_name . '.php';
5+
}
6+
7+
class Client {
8+
9+
function __construct() {
10+
$mo=new TmFac();
11+
$mo->templateMethod();
12+
}
13+
}
14+
15+
$worker=new Client();
16+
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
//Creator.php
3+
abstract class Creator {
4+
5+
protected abstract function factoryMethod();
6+
7+
public function doFactory() {
8+
$mfg= $this->factoryMethod();
9+
return $mfg;
10+
}
11+
12+
}
13+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
//GraphicFactory.php
3+
class GraphicFactory extends Creator {
4+
5+
protected function factoryMethod() {
6+
$product=new GraphicProduct();
7+
return($product->getProperties());
8+
}
9+
10+
}
11+
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
//GraphicProduct.php
3+
class GraphicProduct implements Product {
4+
5+
private $mfgProduct;
6+
7+
public function getProperties() {
8+
$this->mfgProduct="<img src='../pix/genious.jpg'>";
9+
return $this->mfgProduct;
10+
}
11+
12+
}
13+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
//Product.php
3+
interface Product {
4+
public function getProperties();
5+
}
6+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
//TextFactory.php
3+
class TextFactory extends Creator {
4+
5+
protected function factoryMethod() {
6+
$product=new TextProduct();
7+
return($product->getProperties());
8+
}
9+
10+
}
11+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
//TextProduct.php
3+
class TextProduct implements Product {
4+
5+
private $mfgProduct;
6+
7+
public function getProperties() {
8+
$this->mfgProduct ="<div style='color:#cc0000; font-size:12px;
9+
font-family:Verdana, Geneva, sans-serif'>
10+
<strong><em>Caption:</em></strong> Modigliani
11+
painted elongated faces.</div>";
12+
13+
return $this->mfgProduct;
14+
}
15+
16+
}
17+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
//TmAb.php
3+
//Abstract Template Method class
4+
abstract class TmAb {
5+
6+
protected $pix;
7+
8+
protected $cap;
9+
10+
public function templateMethod() {
11+
$this->addPix();
12+
$this->addCaption();
13+
}
14+
15+
protected abstract function addPix();
16+
17+
protected abstract function addCaption();
18+
}
19+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
//TmFac.php
3+
//Concrete Template Method
4+
//invokes Factory Method
5+
class TmFac extends TmAb {
6+
7+
protected function addPix() {
8+
$this->pix=new GraphicFactory();
9+
echo $this->pix->doFactory();
10+
}
11+
12+
protected function addCaption() {
13+
$this->cap=new TextFactory();
14+
echo $this->cap->doFactory();
15+
}
16+
17+
}
18+
?>
169 KB
Loading

0 commit comments

Comments
 (0)