Design Pattern 9-Strategy

xiaoxiao2021-03-06  59

Using system;

namespace Pattern {///

/// Summary description for Class1 /// 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 mode // 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 ());

转载请注明原文地址:https://www.9cbs.com/read-113099.html

New Post(0)