質問編集履歴
1
コードハイライト修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,179 +28,235 @@
|
|
28
28
|
|
29
29
|
Sample.java
|
30
30
|
|
31
|
+
```java
|
32
|
+
|
33
|
+
package sample;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
public class Sample {
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
/////////////////////////////////////////////////////////
|
44
|
+
|
45
|
+
//
|
46
|
+
|
47
|
+
// 抽象クラス
|
48
|
+
|
49
|
+
//
|
50
|
+
|
51
|
+
/////////////////////////////////////////////////////////
|
52
|
+
|
53
|
+
abstract class Action {
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
//全処理
|
58
|
+
|
59
|
+
public String exec(String pre, String post) {
|
60
|
+
|
61
|
+
String s;
|
62
|
+
|
63
|
+
s = funcPre(pre);
|
64
|
+
|
65
|
+
s = doExec(s); //個別処理
|
66
|
+
|
67
|
+
return funcPost(post, s);
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//共通処理
|
74
|
+
|
75
|
+
protected String funcPre(String pre){
|
76
|
+
|
77
|
+
return pre + "_";
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
//共通処理
|
84
|
+
|
85
|
+
protected String funcPost(String post, String s){
|
86
|
+
|
87
|
+
return s + "_" + post;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
//個別処理
|
94
|
+
|
95
|
+
abstract public String doExec(String s); //共通引数
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
/////////////////////////////////////////////////////////
|
104
|
+
|
105
|
+
//
|
106
|
+
|
107
|
+
// クラスA
|
108
|
+
|
109
|
+
//
|
110
|
+
|
111
|
+
/////////////////////////////////////////////////////////
|
112
|
+
|
113
|
+
class ActionA extends Action {
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
//個別変数
|
118
|
+
|
119
|
+
private String text;
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
//個別処理
|
124
|
+
|
125
|
+
public String doExec(String s) {
|
126
|
+
|
127
|
+
return s + text + "_ActionA_";
|
128
|
+
|
129
|
+
};
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
//クラスオブジェクト
|
134
|
+
|
135
|
+
public ActionA setArgs(String text) {
|
136
|
+
|
137
|
+
this.text = text;
|
138
|
+
|
139
|
+
return this;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
public String funcA(String pre, String post, String text){
|
148
|
+
|
149
|
+
return new ActionA().setArgs(text).exec(pre, post);
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
/////////////////////////////////////////////////////////
|
158
|
+
|
159
|
+
//
|
160
|
+
|
161
|
+
// クラスB
|
162
|
+
|
163
|
+
//
|
164
|
+
|
165
|
+
/////////////////////////////////////////////////////////
|
166
|
+
|
167
|
+
class ActionB extends Action {
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
//個別変数
|
172
|
+
|
173
|
+
private String text;
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
//個別処理
|
178
|
+
|
179
|
+
public String doExec(String s) {
|
180
|
+
|
181
|
+
return s + text + "_ActionB_";
|
182
|
+
|
183
|
+
};
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
//クラスオブジェクト
|
188
|
+
|
189
|
+
public ActionB setArgs(String text) {
|
190
|
+
|
191
|
+
this.text = text;
|
192
|
+
|
193
|
+
return this;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
public String funcB(String pre, String post, String text){
|
202
|
+
|
203
|
+
return new ActionB().setArgs(text).exec(pre, post);
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
31
211
|
```
|
32
212
|
|
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
|
-
protected String funcPost(String post, String s){
|
86
|
-
|
87
|
-
return s + "_" + post;
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
//個別処理
|
94
|
-
|
95
|
-
abstract public String doExec(String s); //共通引数
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
/////////////////////////////////////////////////////////
|
104
|
-
|
105
|
-
//
|
106
|
-
|
107
|
-
// クラスA
|
108
|
-
|
109
|
-
//
|
110
|
-
|
111
|
-
/////////////////////////////////////////////////////////
|
112
|
-
|
113
|
-
class ActionA extends Action {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
//個別変数
|
118
|
-
|
119
|
-
private String text;
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
//個別処理
|
124
|
-
|
125
|
-
public String doExec(String s) {
|
126
|
-
|
127
|
-
return s + text + "_ActionA_";
|
128
|
-
|
129
|
-
};
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
//クラスオブジェクト
|
134
|
-
|
135
|
-
public ActionA setArgs(String text) {
|
136
|
-
|
137
|
-
this.text = text;
|
138
|
-
|
139
|
-
return this;
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
public String funcA(String pre, String post, String text){
|
148
|
-
|
149
|
-
return new ActionA().setArgs(text).exec(pre, post);
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
/////////////////////////////////////////////////////////
|
158
|
-
|
159
|
-
//
|
160
|
-
|
161
|
-
// クラスB
|
162
|
-
|
163
|
-
//
|
164
|
-
|
165
|
-
/////////////////////////////////////////////////////////
|
166
|
-
|
167
|
-
class ActionB extends Action {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
//個別変数
|
172
|
-
|
173
|
-
private String text;
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
//個別処理
|
178
|
-
|
179
|
-
public String doExec(String s) {
|
180
|
-
|
181
|
-
return s + text + "_ActionB_";
|
182
|
-
|
183
|
-
};
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
//クラスオブジェクト
|
188
|
-
|
189
|
-
public ActionB setArgs(String text) {
|
190
|
-
|
191
|
-
this.text = text;
|
192
|
-
|
193
|
-
return this;
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
public String funcB(String pre, String post, String text){
|
202
|
-
|
203
|
-
return new ActionB().setArgs(text).exec(pre, post);
|
213
|
+
|
214
|
+
|
215
|
+
--------------------------------------
|
216
|
+
|
217
|
+
Main.java
|
218
|
+
|
219
|
+
```java
|
220
|
+
|
221
|
+
package main;
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
import sample.*;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
public class Main {
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
public static void main(String[] args) {
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
Sample sample = new Sample();
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
String pre = "接頭語";
|
242
|
+
|
243
|
+
String post = "接尾語";
|
244
|
+
|
245
|
+
String text = "ああああ";
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
String s1 = sample.funcA(pre, post, text);
|
250
|
+
|
251
|
+
String s2 = sample.funcB(pre, post, text);
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
System.out.println(s1);
|
256
|
+
|
257
|
+
System.out.println(s2);
|
258
|
+
|
259
|
+
|
204
260
|
|
205
261
|
}
|
206
262
|
|
@@ -214,68 +270,12 @@
|
|
214
270
|
|
215
271
|
--------------------------------------
|
216
272
|
|
273
|
+
実行結果
|
274
|
+
|
217
|
-
|
275
|
+
```java
|
276
|
+
|
277
|
+
接頭語_ああああ_ActionA__接尾語
|
278
|
+
|
279
|
+
接頭語_ああああ_ActionB__接尾語
|
218
280
|
|
219
281
|
```
|
220
|
-
|
221
|
-
package main;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
import sample.*;
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
public class Main {
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
public static void main(String[] args) {
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
Sample sample = new Sample();
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
String pre = "接頭語";
|
242
|
-
|
243
|
-
String post = "接尾語";
|
244
|
-
|
245
|
-
String text = "ああああ";
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
String s1 = sample.funcA(pre, post, text);
|
250
|
-
|
251
|
-
String s2 = sample.funcB(pre, post, text);
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
System.out.println(s1);
|
256
|
-
|
257
|
-
System.out.println(s2);
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
```
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
--------------------------------------
|
272
|
-
|
273
|
-
実行結果
|
274
|
-
|
275
|
-
```
|
276
|
-
|
277
|
-
接頭語_ああああ_ActionA__接尾語
|
278
|
-
|
279
|
-
接頭語_ああああ_ActionB__接尾語
|
280
|
-
|
281
|
-
```
|