Design Pattern 9-strategy

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());

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章