模式乱写之1: 静态工厂模式VS工厂方法模式 Static Factory VS Factory Method
1.静态工厂通过静态方法创建对象,但是不符合OCP
1 public class StaticFactory
2
3 {
4
5 public static Book CreateComputerBookInstance()
6
7 {
8
9 return new ComputerBook();
10
11 }
12
13
14
15 public static Book CreateArtBookInstance()
16
17 {
18
19 return new ArtBook();
20
21 }
22
23
24
25 //If we add a new static method here, not compliance with OCP
26
27 }
28
2
3 {
4
5 public static Book CreateComputerBookInstance()
6
7 {
8
9 return new ComputerBook();
10
11 }
12
13
14
15 public static Book CreateArtBookInstance()
16
17 {
18
19 return new ArtBook();
20
21 }
22
23
24
25 //If we add a new static method here, not compliance with OCP
26
27 }
28