-
Notifications
You must be signed in to change notification settings - Fork 10
/
FactoryMethod.rb.html
96 lines (93 loc) · 3.98 KB
/
FactoryMethod.rb.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- Created by htmlize-1.36 in css mode. -->
<html>
<head>
<title>FactoryMethod.rb</title>
<style type="text/css">
<!--
body {
color: #000000;
background-color: #ffffff;
}
.function-name {
/* font-lock-function-name-face */
color: #0000ff;
}
.keyword {
/* font-lock-keyword-face */
color: #a020f0;
}
.string {
/* font-lock-string-face */
color: #8b2252;
}
.type {
/* font-lock-type-face */
color: #228b22;
}
.variable-name {
/* font-lock-variable-name-face */
color: #a0522d;
}
a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
a:hover {
text-decoration: underline;
}
-->
</style>
</head>
<body>
<pre>
<span class="keyword">class</span> <span class="type">Printer</span>
<span class="keyword">def</span> <span class="function-name">print_header</span>(header)
<span class="keyword">end</span>
<span class="keyword">def</span> <span class="function-name">print_body</span>(body)
<span class="keyword">end</span>
<span class="keyword">def</span> <span class="function-name">print_footer</span>(footer)
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">AsciiPrinter</span> < <span class="type">Printer</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">AsciiDraftPrinter</span> < <span class="type">AsciiPrinter</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">PostScriptPrinter</span> < <span class="type">Printer</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">PostScriptDraftPrinter</span> < <span class="type">PostScriptPrinter</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">Report</span>
<span class="keyword">def</span> <span class="function-name">get_printer</span>(type)
<span class="keyword">throw</span> <span class="string">"Abstract: Please Overload"</span>
<span class="keyword">end</span>
<span class="keyword">def</span> <span class="function-name">print_report</span>(type)
printer = get_printer(type)
printer.print_header(<span class="variable-name">@header</span>)
printer.print_body(<span class="variable-name">@body</span>)
printer.print_footer(<span class="variable-name">@footer</span>)
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">DraftReport</span> < <span class="type">Report</span>
<span class="keyword">def</span> <span class="function-name">get_printer</span>(type)
<span class="keyword">if</span> (type == <span class="string">"ascii"</span>)
<span class="keyword">return</span> <span class="type">AsciiDraftPrinter</span>.new()
<span class="keyword">elsif</span> (type == <span class="string">"postscript"</span>)
<span class="keyword">return</span> <span class="type">PostScriptDraftPrinter</span>.new()
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">class</span> <span class="type">BasicReport</span> < <span class="type">Report</span>
<span class="keyword">def</span> <span class="function-name">get_printer</span>(type)
<span class="keyword">if</span> (type == <span class="string">"ascii"</span>)
<span class="keyword">return</span> <span class="type">AsciiPrinter</span>.new()
<span class="keyword">elsif</span> (type == <span class="string">"postscript"</span>)
<span class="keyword">return</span> <span class="type">PostScriptPrinter</span>.new()
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="keyword">end</span>
</pre>
</body>
</html>