本站不再更新,歡迎光臨 java開發技術網
          隨筆-230  評論-230  文章-8  trackbacks-0

          Command有很多種實現方式,可以隨便的按便這個規律來自由發揮。
          package com.pdw.pattern;

          import java.util.*;
          import org.apache.commons.lang.StringUtils;

          interface Command{
          ?public void execute();
          }
          interface Parameter{
          ?public? String getCommandType();
          }
          class Engineer implements Command{

          ?public void execute() {
          ??// TODO Auto-generated method stub
          ??System.out.println("Enginer....");
          ?}
          ?
          }


          class Programer implements Command{

          ?public void execute() {
          ??// TODO Auto-generated method stub
          ??System.out.println("Programer....");
          ?}
          ?
          }
          class Doctor implements Command{

          ?public void execute() {
          ??// TODO Auto-generated method stub
          ??System.out.println("Doctor.............");
          ?}
          ?
          }
          class EngineerParameter implements Parameter{

          ?public String getCommandType() {
          ??// TODO Auto-generated method stub
          ??return "Engineer";
          ?}
          ?
          }
          class CommandProduce{
          ?public static List commandList=new ArrayList();
          ?public CommandProduce(){
          ??commandList.add(new Engineer());
          ??commandList.add(new Programer());
          ??commandList.add(new Doctor());
          ?}
          ?public static Command getCommand(Parameter p){
          ??Iterator it=commandList.iterator();
          ??while(it.hasNext()){
          ???Object c=(Object)it.next();
          ???System.out.println(c.getClass().getName());
          ???if(StringUtils.indexOf(c.getClass().getName(),p.getCommandType())>0){
          ????return (Command)c;
          ???}
          ??}
          ??return null;
          ?}
          }
          public class CommandImpl {

          ?public static void main(String[] args) {
          ??// TODO Auto-generated method stub

          ??EngineerParameter ep=new EngineerParameter();
          ??CommandProduce cp=new CommandProduce();
          ??(CommandProduce.getCommand(ep)).execute();
          ?}

          }

          posted on 2006-07-13 23:00 有貓相伴的日子 閱讀(398) 評論(0)  編輯  收藏 所屬分類: Patterns
          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(32)

          隨筆分類(222)

          隨筆檔案(224)

          文章分類(4)

          文章檔案(7)

          相冊

          收藏夾(4)

          最新評論

          閱讀排行榜

          評論排行榜

          本站不再更新,歡迎光臨 java開發技術網
          主站蜘蛛池模板: 来凤县| 盘山县| 尉氏县| 房产| 梁山县| 聂拉木县| 夏邑县| 方山县| 色达县| 石景山区| 保康县| 庆阳市| 中方县| 旬阳县| 宣化县| 嘉鱼县| 菏泽市| 双流县| 民权县| 朝阳县| 许昌县| 丽江市| 泽普县| 社会| 广西| 武清区| 平山县| 林周县| 剑河县| 红河县| 会理县| 上饶市| 黎川县| 石景山区| 荔波县| 泰兴市| 洛浦县| 鄂伦春自治旗| 嫩江县| 华坪县| 玛曲县|