当前位置: 首页 > news >正文

集团网站建设工作方案网件路由器做网站

集团网站建设工作方案,网件路由器做网站,广西建设厅官网站首页,佛山专业做网站公司哪家好对象状态影响对象行为#xff1a; 对象拥有不同的状态#xff0c;往往会行使不同的行为... 动机#xff1a; 在软件构建过程中#xff0c;某些对象的状态如果改变以及其行为也会随之而发生变化#xff0c;比如文档处于只读状态#xff0c;其支…对象状态影响对象行为     对象拥有不同的状态往往会行使不同的行为...                    动机     在软件构建过程中某些对象的状态如果改变以及其行为也会随之而发生变化比如文档处于只读状态其支持的行为和读写状态支持的行为就可能完全不同。     如何在运行时根据对象的状态来透明更改对象的行为而不会为对象操作和状态转化之间引入紧耦合意图  允许一个对象在其内部状态改变时改变它的行为。从而使对象看起来似乎修改了其行为。  ------《设计模式》GOF结构图      适用性     1.一个对象的行为取决于它的状态并且它必须在运行时刻根据状态改变它的行为。 2.一个操作中含有庞大的多分支的等条件语句且这些分支依赖于该对象的状态。这个状态通常用一个或多个枚举常量表示。通常有多个操作包含这一相同的条件结构。State模式将每一个分支放入一个独立的类中。这使得你可根据对象自身的情况将对象的状态作为一个对象这一对象可以不依赖于其他对象而独立变化。代码实现      class MainApp   {     static void Main()     {       // Open a new account       Account account  new Account(Jim Johnson);       // Apply financial transactions       account.Deposit(500.0);       account.Deposit(300.0);       account.Deposit(550.0);       account.PayInterest();       account.Withdraw(2000.00);       account.Withdraw(1100.00);       // Wait for user       Console.Read();     }   }   // State   abstract class State   {     protected Account account;     protected double balance;     protected double interest;     protected double lowerLimit;     protected double upperLimit;     // Properties     public Account Account     {       get{ return account; }       set{ account  value; }     }     public double Balance     {       get{ return balance; }       set{ balance  value; }     }     public abstract void Deposit(double amount);     public abstract void Withdraw(double amount);     public abstract void PayInterest();   }   // ConcreteState   // Account is overdrawn   class RedState : State   {     double serviceFee;     // Constructor     public RedState(State state)     {       this.balance  state.Balance;       this.account  state.Account;       Initialize();     }     private void Initialize()     {       // Should come from a datasource       interest  0.0;       lowerLimit  -100.0;       upperLimit  0.0;       serviceFee  15.00;     }     public override void Deposit(double amount)     {       balance  amount;       StateChangeCheck();     }     public override void Withdraw(double amount)     {       amount  amount - serviceFee;       Console.WriteLine(No funds available for withdrawal!);     }     public override void PayInterest()     {       // No interest is paid     }     private void StateChangeCheck()     {       if (balance  upperLimit)       {         account.State  new SilverState(this);       }     }   }   // ConcreteState   // Silver is non-interest bearing state   class SilverState : State   {     // Overloaded constructors     public SilverState(State state) :       this( state.Balance, state.Account)     {       }     public SilverState(double balance, Account account)     {       this.balance  balance;       this.account  account;       Initialize();     }     private void Initialize()     {       // Should come from a datasource       interest  0.0;       lowerLimit  0.0;       upperLimit  1000.0;     }     public override void Deposit(double amount)     {       balance  amount;       StateChangeCheck();     }     public override void Withdraw(double amount)     {       balance - amount;       StateChangeCheck();     }     public override void PayInterest()     {       balance  interest * balance;       StateChangeCheck();     }     private void StateChangeCheck()     {       if (balance  lowerLimit)       {         account.State  new RedState(this);       }       else if (balance  upperLimit)       {         account.State  new GoldState(this);       }     }   }   // ConcreteState   // Interest bearing state   class GoldState : State   {     // Overloaded constructors     public GoldState(State state)       : this(state.Balance,state.Account)     {       }     public GoldState(double balance, Account account)     {       this.balance  balance;       this.account  account;       Initialize();     }     private void Initialize()     {       // Should come from a database       interest  0.05;       lowerLimit  1000.0;       upperLimit  10000000.0;     }     public override void Deposit(double amount)     {       balance  amount;       StateChangeCheck();     }     public override void Withdraw(double amount)     {       balance - amount;       StateChangeCheck();     }     public override void PayInterest()     {       balance  interest * balance;       StateChangeCheck();     }     private void StateChangeCheck()     {       if (balance  0.0)       {         account.State  new RedState(this);       }       else if (balance  lowerLimit)       {         account.State  new SilverState(this);       }     }   }   // Context   class Account   {     private State state;     private string owner;     // Constructor     public Account(string owner)     {       // New accounts are Silver by default       this.owner  owner;       state  new SilverState(0.0, this);     }     // Properties     public double Balance     {       get{ return state.Balance; }     }     public State State     {       get{ return state; }       set{ state  value; }     }     public void Deposit(double amount)     {       state.Deposit(amount);       Console.WriteLine(Deposited {0:C} --- , amount);       Console.WriteLine( Balance  {0:C}, this.Balance);       Console.WriteLine( Status  {0}\n ,         this.State.GetType().Name);       Console.WriteLine();     }     public void Withdraw(double amount)     {       state.Withdraw(amount);       Console.WriteLine(Withdrew {0:C} --- , amount);       Console.WriteLine( Balance  {0:C}, this.Balance);       Console.WriteLine( Status  {0}\n ,         this.State.GetType().Name);     }     public void PayInterest()     {       state.PayInterest();       Console.WriteLine(Interest Paid --- );       Console.WriteLine( Balance  {0:C}, this.Balance);       Console.WriteLine( Status  {0}\n ,         this.State.GetType().Name);     }   } 结果     State模式的几个要点     1.State模式将所有一个特定状态相关的行为都放入一个State的子类对象中在对象状态切换时切换相应的对象;但同时维持State的接口这样实现了具体操作与状态转换之间的解耦。     2.为不同的状态引入不同的对象使得状态转换变得更加明确而且可以保证不会出现状态不一致的情况因为转换是原子性的----即要么彻底转换过来要么不转换。     3.如果State对象没有实例变量那么各个上下文可以共享 同一个State对象从而节省对象开销。
http://www.yutouwan.com/news/243393/

相关文章:

  • 河南网站备案系统短信wordpress模板导航栏
  • 企业网站建设的一般原则包括黄山网站建设公司
  • 公司域名注册网站哪个好哪一个网站可以做专利检索报告
  • 网站浮窗制作室内设计平面图素材
  • 网站首页英文汕头市企业网站建设服务机构
  • 什么叫网站策划书wordpress个人版
  • 有什么展厅设计做的好的网站网站建设公司推荐理由
  • 怎样在百度上做免费推广seo网站推广计划
  • 小企业网站建设响应式科技公司网站模板
  • 微信网站制作企业云服务器一般多少钱
  • 西宁做网站君博解决长沙传媒公司招聘
  • 云主机 多个网站潍坊做网页的公司
  • 珠海自适应网站建设WordPress主题开发核心知识
  • 先做网站再付款wordpress入门
  • 营销型网站建设 价格网站开发收获
  • 做物流网站多少钱明星百度指数排名
  • 视频优化是什么意思优化外包哪里好
  • 私人为别人做网站违法问题麻花星空影视传媒制作公司网站
  • 商城型网站的概念如何选择合肥网络公司
  • 知名的家居行业网站开发vi形象设计包括什么
  • 高端品牌网站建设有哪些网站优化千牛帮
  • 如果建设一个网站wordpress增加付费阅读
  • wordpress如何看主题wordpress可以做seo吗
  • 官方网站下载穿越火线wordpress怎样用
  • wordpress 数字指纹百度快照seo
  • 建网站公司公司名称大全网站网络营销推广商城
  • 网站 如何做 同时在线网站的常用技术有哪些
  • 网站页面架构成都官网优化推广
  • 青岛网站建设新元创想手机版做我女朋友网站
  • 网站建设也笔试做设计兼职的网站有哪些工作