模式乱写之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 

 

posted @ 2008-07-21 11:15  许晓光  阅读(275)  评论(0编辑  收藏  举报