File tree Expand file tree Collapse file tree 5 files changed +18
-34
lines changed
SandersW-LearningPHPDesignPatterns/Factory Expand file tree Collapse file tree 5 files changed +18
-34
lines changed Original file line number Diff line number Diff line change 9
9
//GraphicFactory.php
10
10
include_once ('Creator.php ' );
11
11
include_once ('GraphicProduct.php ' );
12
+
12
13
class GraphicFactory extends Creator {
13
14
14
15
protected function factoryMethod () {
Original file line number Diff line number Diff line change 1
1
<?php
2
2
//GraphicProduct.php
3
3
include_once ('Product.php ' );
4
+
4
5
class GraphicProduct implements Product {
5
6
6
7
private $ mfgProduct ;
8
+
7
9
public function getProperties () {
8
10
$ this ->mfgProduct ="This is a graphic.<3 " ;
9
11
return $ this ->mfgProduct ;
10
12
}
11
-
12
13
}
Original file line number Diff line number Diff line change 1
1
<?php
2
- //TextProduct.php
3
- include_once ('Product.php ' );
4
- class TextProduct implements Product {
5
-
6
- private $ mfgProduct ;
7
- public function getProperties ()
8
- {
9
- $ this ->mfgProduct ="This is text. " ;
10
- return $ this ->mfgProduct ;
11
- }
2
+ //Product.php
3
+ interface Product {
12
4
5
+ public function getProperties ();
13
6
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- /*
4
- * To change this license header, choose License Headers in Project Properties.
5
- * To change this template file, choose Tools | Templates
6
- * and open the template in the editor.
7
- */
8
-
3
+ //TextFactory.php
9
4
include_once ('Creator.php ' );
10
5
include_once ('TextProduct.php ' );
11
6
12
7
class TextFactory extends Creator {
13
8
14
9
protected function factoryMethod () {
15
- $ product =new TextProduct ();
16
- return ($ product ->getProperties ());
10
+ $ product =new TextProduct ();
11
+ return ($ product ->getProperties ());
17
12
}
18
13
19
- }
20
-
14
+ }
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- /*
4
- * To change this license header, choose License Headers in Project Properties.
5
- * To change this template file, choose Tools | Templates
6
- * and open the template in the editor.
7
- */
3
+ //TextProduct.php
4
+ include_once ('Product.php ' );
8
5
9
- include_once ('Creator.php ' );
10
- include_once ('TextProduct.php ' );
6
+ class TextProduct implements Product {
11
7
12
- class TextFactory extends Creator {
8
+ private $ mfgProduct ;
13
9
14
- protected function factoryMethod () {
15
- $ product = new TextProduct () ;
16
- return ( $ product -> getProperties ()) ;
10
+ public function getProperties () {
11
+ $ this -> mfgProduct = " This is text. " ;
12
+ return $ this -> mfgProduct ;
17
13
}
18
14
19
- }
20
-
15
+ }
You can’t perform that action at this time.
0 commit comments