-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFactoryMethod.rb
76 lines (73 loc) · 1.35 KB
/
FactoryMethod.rb
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
class Printer
def print_header(header)
puts(header)
end
def print_body(body)
puts(body)
end
def print_footer(footer)
puts(footer)
end
end
class AsciiPrinter < Printer
end
class AsciiDraftPrinter < AsciiPrinter
def print_header(header)
end
def print_footer(header)
end
end
class PostScriptPrinter < Printer
end
class PostScriptDraftPrinter < PostScriptPrinter
def print_header(header)
end
def print_footer(header)
end
end
class Report
def header()
"header"
end
def body()
"body"
end
def footer()
"footer"
end
def get_printer(type)
throw "Abstract: Please Overload"
end
def print_report(type)
printer = get_printer(type)
printer.print_header(header)
printer.print_body(body)
printer.print_footer(footer)
end
end
class DraftReport < Report
def get_printer(type)
if (type == "ascii")
return AsciiDraftPrinter.new()
elsif (type == "postscript")
return PostScriptDraftPrinter.new()
end
end
end
class BasicReport < Report
def get_printer(type)
if (type == "ascii")
return AsciiPrinter.new()
elsif (type == "postscript")
return PostScriptPrinter.new()
end
end
end
puts("Draft")
d = DraftReport.new()
d.print_report("ascii")
d.print_report("postscript")
puts("Basic")
b = BasicReport.new()
b.print_report("ascii")
b.print_report("postscript")