-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestAbstractFactory.java
More file actions
47 lines (46 loc) · 890 Bytes
/
Copy pathTestAbstractFactory.java
File metadata and controls
47 lines (46 loc) · 890 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
package design.pattern;
interface Cpu{
void process();
}
interface CpuFactory{
Cpu produceCpu();
}
class AmdCpu implements Cpu{
public void process() {
System.out.println("Amd is processing");
}
}
class InterCpu implements Cpu{
public void process() {
System.out.println("Inter is processing");
}
}
class AmdFactory implements CpuFactory{
public Cpu produceCpu() {
return new AmdCpu();
}
}
class IntelFactory implements CpuFactory{
public Cpu produceCpu() {
return new InterCpu();
}
}
class Computer{
Cpu cpu;
public Computer(CpuFactory factory){
cpu = factory.produceCpu();
cpu.process();
}
}
public class TestAbstractFactory {
public static void main(String[] args) {
new Computer(creatSpecificFactory());
}
public static CpuFactory creatSpecificFactory(){
int sys = 0;
if(sys == 0)
return new AmdFactory();
else
return new IntelFactory();
}
}