forked from sermakov/JavaPatternMirea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsk6.java
More file actions
99 lines (69 loc) · 2.15 KB
/
tsk6.java
File metadata and controls
99 lines (69 loc) · 2.15 KB
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
97
98
99
package some;
public class tsk6 {
static void prt(Object a) { System.out.println(a); }
@SuppressWarnings("unused")
public static void main(String[] args) {
FctPrd a = FctCrt.crt();
Pra b = Fct.a.pra();
Prb c = Fct.a.prb();
Obj d = new Obj.ObjBld()
.stA(0)
.stB(0)
.stC(0)
.bld();
PrtSb e = new PrtSb();
e.b = 3;
PrtSb f = (PrtSb) e.cln();
prt("" + (e.b == f.b) + ' ' + (e == f));
}
////////////////////////////////////////////////////
interface FctPrd {}
static class FctActPrd implements FctPrd {}
static class FctCrt {
static FctPrd crt() { return new FctActPrd(); }
}
////////////////////////////////////////////////////
interface Pra {}
interface Prb {}
static class Prda implements Pra {}
static class Prdb implements Prb {}
interface IFct {
Pra pra();
Prb prb();
}
static class Fct implements IFct {
static final IFct a = new Fct();
private Fct() {}
@Override public Pra pra() { return new Prda(); }
@Override public Prb prb() { return new Prdb(); }
}
////////////////////////////////////////////////////
static class Obj {
Obj(int a, int b, int c) {}
static class ObjBld {
private int a;
private int b;
private int c;
ObjBld stA(int _a) { a = _a; return this; }
ObjBld stB(int _b) { b = _b; return this; }
ObjBld stC(int _c) { c = _c; return this; }
Obj bld() { return new Obj(a, b, c); }
}
}
////////////////////////////////////////////////////
interface IPrt {
IPrt cln();
}
static class Prt implements IPrt {
private int a = 1;
Prt() {}
Prt(Prt b) { a = b.a; }
@Override public IPrt cln() { return new Prt(this); }
}
static class PrtSb extends Prt {
private int b = 2;
PrtSb() {}
public PrtSb(PrtSb c) { super(c); b = c.b; }
@Override public IPrt cln() { return new PrtSb(this); }
}
}