File tree Expand file tree Collapse file tree 4 files changed +86
-0
lines changed
SandersW-LearningPHPDesignPatterns/template_method_pattern/minimal_example Expand file tree Collapse file tree 4 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
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
+
9
+ /**
10
+ * Description of AbstractClass
11
+ *
12
+ * @author Anit Shrestha
13
+ */
14
+ abstract class AbstractClass {
15
+
16
+ protected $ pix ;
17
+
18
+ protected $ cap ;
19
+
20
+ public function templateMethod ($ pixNow , $ capNow ) {
21
+ $ this ->pix =$ pixNow ;
22
+ $ this ->cap =$ capNow ;
23
+ $ this ->addPix ($ this ->pix );
24
+ $ this ->addCaption ($ this ->cap );
25
+ }
26
+
27
+ abstract protected function addPix ($ pix );
28
+
29
+ abstract protected function addCaption ($ cap );
30
+
31
+ }
32
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
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
+
9
+ function __autoload ($ class_name ) {
10
+ include $ class_name . '.php ' ;
11
+ }
12
+
13
+ class Client {
14
+
15
+ function __construct () {
16
+ $ caption ="Modigliani painted elongated faces. " ;
17
+
18
+ $ mo =new ConcreteClass ();
19
+ $ mo ->templateMethod ("genious.jpg " , $ caption );
20
+ }
21
+ }
22
+
23
+ $ worker =new Client ();
24
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
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
+
9
+ /**
10
+ * Description of ConcreteClass
11
+ *
12
+ * @author Anit Shrestha
13
+ */
14
+ include_once ('AbstractClass.php ' );
15
+
16
+ class ConcreteClass extends AbstractClass {
17
+
18
+ protected function addPix ($ pix ) {
19
+ $ this ->pix =$ pix ;
20
+ $ this ->pix = "pix/ " . $ this ->pix ;
21
+ $ formatter = "<img src= $ this ->pix ><br/> " ;
22
+ echo $ formatter ;
23
+ }
24
+
25
+ protected function addCaption ($ cap ) {
26
+ $ this ->cap =$ cap ;
27
+ echo "<em>Caption:</em> " . $ this ->cap . "<br/> " ;
28
+ }
29
+ }
30
+ ?>
You can’t perform that action at this time.
0 commit comments