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

物流网站建设模板下载c2c模式是指什么

物流网站建设模板下载,c2c模式是指什么,网页设计与制作课程思政项目构建,快递空包网站建设文章目录一、引入二、状态模式2.1 Intent 意图2.2 Applicability 适用性2.3 类图2.4 Collaborations 合作2.5 Implementation 实现2.5 状态模式与策略模式的对比2.5 状态模式实例#xff1a;糖果机2.6 状态模式实例#xff1a;自行车升降档一、引入 State Diagram 状态图糖果机2.6 状态模式实例自行车升降档一、引入 State Diagram 状态图 A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. 状态图是在计算机科学和相关领域中用于描述系统行为的一种图. Parts of UML 糖果机问题 状态汇总No Quarter无 25 美分、Has Quarter有 25 美分、Gumball Sold糖果售出、Out Of Gumballs糖果售罄attribute value行为汇总insert quarter投币、ejects quarter吐币、turns crank转动曲柄、dispense出糖果For machinemethod package net.dp.state.gumball;public class GumballMachine {final static int SOLD_OUT 0;final static int NO_QUARTER 1;final static int HAS_QUARTER 2;final static int SOLD 3;int state SOLD_OUT;int count 0;public GumballMachine(int count) {this.count count;if (count 0) {state NO_QUARTER;}}public void insertQuarter() {if (state HAS_QUARTER) {System.out.println(You cant insert another quarter);} else if (state NO_QUARTER) {state HAS_QUARTER;System.out.println(You inserted a quarter);} else if (state SOLD_OUT) {System.out.println(You cant insert a quarter, the machine is sold out);} else if (state SOLD) {System.out.println(Please wait, were already giving you a gumball);}}public void ejectQuarter() {if (state HAS_QUARTER) {System.out.println(Quarter returned);state NO_QUARTER;} else if (state NO_QUARTER) {System.out.println(You havent inserted a quarter);} else if (state SOLD) {System.out.println(Sorry, you already turned the crank);} else if (state SOLD_OUT) {System.out.println(You cant eject, you havent inserted a quarter yet);}}public void turnCrank() {if (state SOLD) {System.out.println(Turning twice doesnt get you another gumball!);} else if (state NO_QUARTER) {System.out.println(You turned but theres no quarter);} else if (state SOLD_OUT) {System.out.println(You turned, but there are no gumballs);} else if (state HAS_QUARTER) {System.out.println(You turned...);state SOLD;dispense();}}public void dispense() {if (state SOLD) {System.out.println(A gumball comes rolling out the slot);count count - 1;if (count 0) {System.out.println(Oops, out of gumballs!);state SOLD_OUT;} else {state NO_QUARTER;}} else if (state NO_QUARTER) {System.out.println(You need to pay first);} else if (state SOLD_OUT) {System.out.println(No gumball dispensed);} else if (state HAS_QUARTER) {System.out.println(No gumball dispensed);}}public void refill(int numGumBalls) {this.count numGumBalls;state NO_QUARTER;}public String toString() {StringBuffer result new StringBuffer();result.append(\nMighty Gumball, Inc.);result.append(\nJava-enabled Standing Gumball Model #2004\n);result.append(Inventory: count gumball);if (count ! 1) {result.append(s);}result.append(\nMachine is );if (state SOLD_OUT) {result.append(sold out);} else if (state NO_QUARTER) {result.append(waiting for quarter);} else if (state HAS_QUARTER) {result.append(waiting for turn of crank);} else if (state SOLD) {result.append(delivering a gumball);}result.append(\n);return result.toString();} } Terrible implements 需求变更 提升销量10 % 的可能出两个糖果 难以维护 二、状态模式 2.1 Intent 意图 Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. 状态模式允许一个对象在其内部状态改变的时候改变其行为这个对象看上去就像改变了它的类一样. 2.2 Applicability 适用性 An object’s behavior depends on its state, and it must change its behavior at run-time depending on that state. 对象的行为取决于它的状态它必须根据运行状态改变它的行为.Operations have large, multipart conditional statements that depend on the object’s state. 操作有依赖于对象状态的大量的、多部分的条件语句. 2.3 类图 Context: Defines the interface of interest to clients; maintains an instance of a ConcreteState that defines the current state.State: Defines an interface for encapsulating the behavior associated with a particular state of the Context.ConcreteState: each implements a behavior associated with a state of the Context. 2.4 Collaborations 合作 Context delegates state-specific requests to the current ConcreteState object. Context 把状态相关的请求代理到当前的 ConcreteState 对象。A context may pass itself as an argument to the State object handling the request. This lets the State object access the context if necessary. context 可以将自身作为参数传递给处理该请求的状态对象以允许状态对象在必要时访问上下文。Context is the primary interface for clients. State objects can be configured to context. Once a context is configured, its clients don’t have to deal with the State objects directly. Context 是 Client 的主要接口状态对象可以配置到 context并且一旦配置了状态Client 就不必直接处理状态对象了。Either Context or the ConcreteState can decide which state succeeds another and under what circumstances. Context 或 ConcreateState 均能决定 state 的后继状态是哪个以及在什么条件下状态的变化如何 2.5 Implementation 实现 Who defines the state transitions? 谁定义状态转换 The State pattern does not specify which participant defines the criteria for state transitions. 状态模式并不指定哪个参与者Context、State定义了状态转换的标准.If the criteria are fixed, then they can be implemented entirely in the Context. 如果转换标准是固定的那么它们就可以完全在 Context 中实现.It is generally more flexible and appropriate to let the State subclasses themselves specify their successor state and when to make the transition. 通常让状态子类本身指定它们的后继状态以及何时进行转换更加灵活和合适. It is easy to modify or extend the logic by defining new State subclasses. 易于通过定义新 State 子类修改或扩展逻辑A disadvantage is State subclass will have knowledge of at least one other, which introduces implementation dependencies between subclasses. 一个缺点是状态子类至少知道一个其他子类这就引入了子类之间的实现依赖关系。 Creating and destroying State objects. 创建与销毁状态对象 Lazy: to create State objects only when they are needed and destroy them thereafter. 只在需要状态对象时创建状态对象并在此之后销毁它们 When the states that will be entered aren’t known at runtime, and contexts change state infrequently. 当运行时不知道将输入的状态且上下文 contexts 很少改变状态时. Eager: creating them ahead of time and never destroying them. 提前创造出它们但从不摧毁它们 When state changes occur rapidly. 状态改变频繁时 2.5 状态模式与策略模式的对比 Same类图基本一致Diff Strategy: One state with many algorithms 一个具有多个算法实现的抽象状态采用哪个由 Client 决定 State: many States with different behaviors - 多个 具有不同行为的状态一个状态对应一个行为 采用哪个可以由 Client 决定且运行过程中状态可以改变从而行为也得到改变 状态模式与策略模式很相似状态是将类的状态封装了起来在执行动作时进行自动的转换从而实现类在不同状态下的同一动作显示出不同结果。 它与策略模式的区别在于这种转换是自动无意识的。 关于策略模式https://blog.csdn.net/qq_44992559/article/details/115007554 2.5 状态模式实例糖果机 变更需求实现 糖果机即 Context public class GumballMachine {State soldOutState;State noQuarterState;State hasQuarterState;State soldState;State winnerState;State state soldOutState;int count 0;public GumballMachine(int numberGumballs) {soldOutState new SoldOutState(this);noQuarterState new NoQuarterState(this);hasQuarterState new HasQuarterState(this);soldState new SoldState(this);winnerState new WinnerState(this);this.count numberGumballs;if (numberGumballs 0) {state noQuarterState;} }public void insertQuarter() {state.insertQuarter();}public void ejectQuarter() {state.ejectQuarter();}public void turnCrank() {state.turnCrank();state.dispense();}void setState(State state) {this.state state;}void releaseBall() {System.out.println(A gumball comes rolling out the slot...);if (count ! 0) {count count - 1;}}int getCount() {return count;}void refill(int count) {this.count count;state noQuarterState;}public State getState() {return state;}public State getSoldOutState() {return soldOutState;}public State getNoQuarterState() {return noQuarterState;}public State getHasQuarterState() {return hasQuarterState;}public State getSoldState() {return soldState;}public State getWinnerState() {return winnerState;}public String toString() {StringBuffer result new StringBuffer();result.append(\nMighty Gumball, Inc.);result.append(\nJava-enabled Standing Gumball Model #2004);result.append(\nInventory: count gumball);if (count ! 1) {result.append(s);}result.append(\n);result.append(Machine is state \n);return result.toString();} } 糖果机状态接口抽象状态 public interface State {public void insertQuarter();public void ejectQuarter();public void turnCrank();public void dispense(); }有 25 美分硬币状态 public class HasQuarterState implements State {Random randomWinner new Random(System.currentTimeMillis());GumballMachine gumballMachine;public HasQuarterState(GumballMachine gumballMachine) {this.gumballMachine gumballMachine;}public void insertQuarter() {System.out.println(You cant insert another quarter);}public void ejectQuarter() {System.out.println(Quarter returned);gumballMachine.setState(gumballMachine.getNoQuarterState());}public void turnCrank() {System.out.println(You turned...);int winner randomWinner.nextInt(10);if ((winner 0) (gumballMachine.getCount() 1)) {gumballMachine.setState(gumballMachine.getWinnerState());} else {gumballMachine.setState(gumballMachine.getSoldState());}}public void dispense() {System.out.println(No gumball dispensed);}public String toString() {return waiting for turn of crank;} } 无 25 美分硬币状态 public class NoQuarterState implements State {GumballMachine gumballMachine;public NoQuarterState(GumballMachine gumballMachine) {this.gumballMachine gumballMachine;}public void insertQuarter() {System.out.println(You inserted a quarter);gumballMachine.setState(gumballMachine.getHasQuarterState());}public void ejectQuarter() {System.out.println(You havent inserted a quarter);}public void turnCrank() {System.out.println(You turned, but theres no quarter);}public void dispense() {System.out.println(You need to pay first);} public String toString() {return waiting for quarter;} }售罄状态 public class SoldOutState implements State {GumballMachine gumballMachine;public SoldOutState(GumballMachine gumballMachine) {this.gumballMachine gumballMachine;}public void insertQuarter() {System.out.println(You cant insert a quarter, the machine is sold out);}public void ejectQuarter() {System.out.println(You cant eject, you havent inserted a quarter yet);}public void turnCrank() {System.out.println(You turned, but there are no gumballs);}public void dispense() {System.out.println(No gumball dispensed);}public String toString() {return sold out;} }售卖出状态 public class SoldState implements State {GumballMachine gumballMachine;public SoldState(GumballMachine gumballMachine) {this.gumballMachine gumballMachine;}public void insertQuarter() {System.out.println(Please wait, were already giving you a gumball);}public void ejectQuarter() {System.out.println(Sorry, you already turned the crank);}public void turnCrank() {System.out.println(Turning twice doesnt get you another gumball!);}public void dispense() {gumballMachine.releaseBall();if (gumballMachine.getCount() 0) {gumballMachine.setState(gumballMachine.getNoQuarterState());} else {System.out.println(Oops, out of gumballs!);gumballMachine.setState(gumballMachine.getSoldOutState());}}public String toString() {return dispensing a gumball;} }Winner 状态出两糖状态 public class WinnerState implements State {GumballMachine gumballMachine;public WinnerState(GumballMachine gumballMachine) {this.gumballMachine gumballMachine;}public void insertQuarter() {System.out.println(Please wait, were already giving you a Gumball);}public void ejectQuarter() {System.out.println(Please wait, were already giving you a Gumball);}public void turnCrank() {System.out.println(Turning again doesnt get you another gumball!);}public void dispense() {System.out.println(YOURE A WINNER! You get two gumballs for your quarter);gumballMachine.releaseBall();if (gumballMachine.getCount() 0) {gumballMachine.setState(gumballMachine.getSoldOutState());} else {gumballMachine.releaseBall();if (gumballMachine.getCount() 0) {gumballMachine.setState(gumballMachine.getNoQuarterState());} else {System.out.println(Oops, out of gumballs!);gumballMachine.setState(gumballMachine.getSoldOutState());}}}public String toString() {return despensing two gumballs for your quarter, because YOURE A WINNER!;} } 2.6 状态模式实例自行车升降档 可以将自身作为参数传递给处理该请求的状态对象以允许状态对象在必要时访问上下文 状态转换交给 State 自行车即 Context public class Bike {private GearState gearState;public Bike(GearState gearState) {this.gearState gearState;}public GearState getGearState() {return gearState;}public void setGearState(GearState gearState) {this.gearState gearState;}public void gearUp() {gearState.gearUp(this);}public void gearDown() {gearState.gearDown(this);} } 档数状态抽象状态 /*** 档数状态*/ public abstract class GearState {public GearState() {}// 升档public abstract void gearUp(Bike bike);// 降档public abstract void gearDown(Bike bike); }档数状态实现类 public class FirstGearState extends GearState {Overridepublic void gearUp(Bike bike) {System.out.print(Moving Up from FirstGear to SecondGear!\t);bike.setGearState(new SecondGearState());System.out.println(Current GearState: bike.getGearState().toString());}Overridepublic void gearDown(Bike bike) {System.out.print(Already in the FirstGear - cannot go lower!\t);System.out.println(Current GearState: bike.getGearState().toString());}Overridepublic String toString() {return First Gear;} } public class SecondGearState extends GearState {Overridepublic void gearUp(Bike bike) {System.out.print(Moving Up from SecondGear to ThirdGear!\t);bike.setGearState(new ThirdGearState());System.out.println(Current GearState: bike.getGearState().toString());}Overridepublic void gearDown(Bike bike) {System.out.print(Moving Down from SecondGear to FirstGear!\t);bike.setGearState(new FirstGearState());System.out.println(Current GearState: bike.getGearState().toString());}Overridepublic String toString() {return Second Gear;} } public class ThirdGearState extends GearState {Overridepublic void gearUp(Bike bike) {System.out.print(Already in the ThirdGear - cannot go higher!\t);System.out.println(Current GearState: bike.getGearState().toString());}Overridepublic void gearDown(Bike bike) {System.out.println(Moving Down from ThirdGear to SecondGear!\t);bike.setGearState(new SecondGearState());System.out.println(Current GearState: bike.getGearState().toString());}Overridepublic String toString() {return Third Gear;} } Client 测试 public class StateClientDemo {public static void main(String[] args) {Bike bike new Bike(new SecondGearState());bike.gearDown();bike.gearDown();bike.gearDown();bike.gearUp();bike.gearUp();bike.gearUp();bike.gearUp();} }
http://www.lakalapos1.cn/news/22021/

相关文章:

  • 莱阳做网站的农业网站建设模板
  • 资讯网站建设流程秦皇岛网络推广公司
  • 温州网站建设专业的公司兰州新区规划建设管理局网站
  • 有关设计的网站wordpress新添接口
  • 有关网站设计的文章12306网站 花了多少钱建设
  • 做网站的外包能学到什么查服务器ip地址
  • 网站专项审批查询网站建设后的效果评估
  • 媒体网站推进信息化建设seo综合
  • 网站建设一条龙ue365受欢迎的唐山网站建设
  • 六安品牌网站建设怎么样阿里wordpress镜像源码
  • 中国建设银行网站北京网点柳州seo公司
  • 广州建设厅官方网站阿里云 oss做网站
  • 岳阳网站设计买网站名称
  • 青海省公路建设服务网站郑州老牌做企业网站
  • 兰州道路建设情况网站软文范例大全200字
  • 如何做网站 seo手机上传视频网站开发
  • 购物网站开发中查看订单的实现逻辑上海知名的网站建设
  • 免费网站模板 下载高埗网站仿做
  • 微软雅黑做网站是否侵权为什么访问外国网站速度慢
  • 网站克隆镜像做关键字seo龙游建设工程信息网站
  • 宜都网站设计鞍山前程无忧招聘网
  • 自建网站和第三方平台做网站的公司什么动力
  • 科技 网站建设网站开发工具软件
  • 网站备案背景布怎样把个人介绍放到百度
  • 公司建一个网站多少钱wordpress 替换
  • 卖东西的网站模板免费下载wordpress素材
  • 网站建设的总结200字百度收录文章
  • 信用徐州网站建设情况网上国网推广方法
  • 网站建设+深圳+凡科公司行业类型有哪些
  • 腐女喜欢做的网站设计公司注册需要什么条件