CSDN博客

img 2002pine

Design Pattern 9-strategy

发表于2004/9/25 17:22:00  1258人阅读

using System;

namespace Pattern
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 public abstract class strategy
 {
  protected string m_oldstr="";
  protected string m_newstr="";
  public void setOldString(string oldstr)
  {
   this.m_oldstr =oldstr;
  }
  public string getNewString()
  {
   return this.m_newstr;
  }
  public abstract void replace();
  
 }

 public class repA:strategy
 {
  public repA()
  {
  }
  public override void replace()
  {
   this.m_newstr =this.m_oldstr+"aaaa";
  }

 }

 public class repB:strategy
 {
  public repB()
  {
  }
  public override void replace()
  {
   this.m_newstr =this.m_oldstr+"bbbb";
  }

 }
}
 //  策略模式
//      strategy r1=new repA();
//      r1.setOldString("good");
//      r1.replace();
//      Console.WriteLine(r1.getNewString());
   //
   //   repB r2=new repB();
   //   r2.setOldString("good");
   //   r2.replace();
   //   Console.WriteLine(r2.getNewString());

阅读全文
0 0

相关文章推荐

img
取 消
img