rednight

          0x2B|~0x2B,That's not a question,Just do it.
          posts - 32, comments - 14, trackbacks - 0, articles - 0

          state pattern

          Posted on 2006-12-26 14:46 rednight 閱讀(349) 評論(0)  編輯  收藏 所屬分類: 工作學習
          The logic to change state is only inside one method (initVesselView(…)) inside GrVessel.java.?

          if (viewType == VIEW_STOWAGE) {
          ??????????? vslView_ = new VesselStowageView(leftPoint, bow2Left, leftCenter,
          ???????????????????????????????????????????? rightCenter, shipWidth_);
          ??????? }
          ??????? else if (viewType == VIEW_SIDE) {
          ??????????? vslView_ = new VesselSideView(leftPoint, bow2Left, leftCenter,
          ????????????????????????????????????????? rightCenter, shipWidth_);
          ??????? }
          ??????? else if (viewType == VIEW_PLAN) {
          ??????????? vslView_ = new VesselPlanView(leftPoint, bow2Left, leftCenter,
          ????????????????????????????????????????? rightCenter, shipWidth_);
          ??????? }
          ??????? else {
          ??????????? throw new IllegalArgumentException(
          ??????????????? "GrVessel::initVesselView-->Invalid view type!");
          ??????? }


          We do not need to repeat this logic of changing view in many other method.
          This is the benefit of State design pattern.
          The 3 state classes here are VesselPlanView.java, VesselSideView.java and VesselStowageView.java

          Please note that in the state classes, if a method is supported by stateA and not supported by stateB.?
          Then, in stateB, the method body will throw an exception (IllegalArgumentException) to indicate that coder call the wrong method in the wrong state.

          Example, in VesselPlanView.java, public boolean addStowage(...).? This method is only meaningful to stowageView.

          public boolean addStowage(IlvManager manager, List transformList, IlvGraphic stowage, String stadBayN,
          ????????????????????????????? boolean isSelect) {
          ??????? throw new IllegalArgumentException(
          ??????????????? "GrVessel::addStowage-->be sure the vessel at stowage view!");
          ??? }


          Hence, in PlanView, the method body will throw exception.

          Just to share with you a better way to code.

          主站蜘蛛池模板: 泗洪县| 璧山县| 甘南县| 龙口市| 邮箱| 霞浦县| 枝江市| 伊宁县| 文山县| 盘山县| 长汀县| 南充市| 界首市| 大竹县| 宁海县| 区。| 大宁县| 潞城市| 阿鲁科尔沁旗| 谢通门县| 沁源县| 阿克陶县| 琼结县| 滕州市| 扶沟县| 蒙城县| 陵水| 拉孜县| 佛山市| 西峡县| 四子王旗| 湟中县| 利辛县| 若尔盖县| 公主岭市| 洪雅县| 手游| 浦北县| 德阳市| 芮城县| 临高县|