博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#设计方法程序.cs

Posted on 2006-05-16 13:36  wander  阅读(297)  评论(0)    收藏  举报


  1using System;
  2using System.Collections;
  3
  4public class MyClass
  5{
  6    public static void Main()
  7    {
  8        Builder builder = new mao();
  9        builder.Build();
 10        builder.result().CreateProduct();
 11        
 12        builder = new shi();
 13        builder.Build();
 14        builder.result().CreateProduct();
 15        
 16        builder = new tie();
 17        builder.Build();
 18        builder.result().CreateProduct();
 19        
 20        Console.WriteLine( "振威镖局建造完毕!镖局金壁辉煌!" );
 21        Console.Read();
 22    }

 23    
 24}

 25
 26interface Builder{
 27    void Build();            //建造方法
 28    Product result();        //返回产品
 29}

 30
 31class mao:Builder{            //毛利求建造者
 32    
 33    //实现建造方法
 34    public void Build(){
 35        Console.WriteLine( "我是毛利求,我是负责财务会计日常开销的." );
 36    }
    
 37    
 38    //返回建造结果
 39    public Product result(){
 40        return new P_mao();        //毛利求完成的产品
 41    }

 42        
 43}

 44
 45class shi:Builder{            //时小迁建造者
 46    
 47    //实现建造方法
 48    public void Build(){
 49        Console.WriteLine( "我是时小迁,我是负责工程的后勤供应的." );
 50    }
    
 51    
 52    //返回建造结果
 53    public Product result(){
 54        return new S_mao();        //时小迁完成的产品
 55    }

 56        
 57}

 58
 59class tie:Builder{            //铁开山建造者
 60    
 61    //实现建造方法
 62    public void Build(){
 63        Console.WriteLine( "我是铁开山,我是负责日常施工监督的." );
 64    }
    
 65    
 66    //返回建造结果
 67    public Product result(){
 68        return new T_mao();        //铁开山完成的产品
 69    }

 70        
 71}

 72
 73interface Product{            //这里是产品接口.
 74    void CreateProduct();
 75}

 76
 77class P_mao:Product{    //毛利求的产品
 78    public P_mao(){
 79        Console.WriteLine( "**************  财务会计日常开销正常开始  **************" );
 80    }

 81    
 82    public void CreateProduct(){
 83        Console.WriteLine( "三月后,财务会计日常开销一切正常,没有超支,而且还节省了50万两白银!\n" );
 84    }

 85    
 86}

 87
 88class S_mao:Product{    //时小迁的产品
 89    public S_mao(){
 90        Console.WriteLine( "**************  工程的后勤供应正常开始  **************" );
 91    }

 92    
 93    public void CreateProduct(){
 94        Console.WriteLine( "三月后,工程的后勤供应一切正常,我跑前跑后,终于把材料都准备齐全!\n" );
 95    }

 96    
 97}

 98
 99class T_mao:Product{    //铁开山的产品
100    public T_mao(){
101        Console.WriteLine( "**************日常施工监督正常开始**************" );
102    }

103    
104    public void CreateProduct(){
105        Console.WriteLine( "三月后,工程的施工一切正常,弟兄们都很配合我,我们施工很顺利!\n" );
106    }

107    
108}