-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.rb
More file actions
63 lines (49 loc) · 728 Bytes
/
Factory.rb
File metadata and controls
63 lines (49 loc) · 728 Bytes
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
class DataType1
def initialize(name)
@name = name
end
def getName
"DataType1:#{@name}"
end
end
class DataType2
def initialize(name)
@name = name
end
def getName
"DataType2:#{@name}"
end
end
class Factory
def initialize(number)
@data = []
number.times do |i|
@data << Data_new(i)
end
end
def getList
@data.each do |v|
puts v.getName
end
end
end
class Data1Factory < Factory
def initialize(number)
super(number)
end
def Data_new(name)
DataType1.new(name)
end
end
class Data2Factory < Factory
def initialize(number)
super(number)
end
def Data_new(name)
DataType2.new(name)
end
end
data1 = Data1Factory.new(3)
data1.getList
data2 = Data2Factory.new(4)
data2.getList