本站不再更新,歡迎光臨 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 有貓相伴的日子 閱讀(402) 評論(0)  編輯  收藏 所屬分類: Patterns
          本站不再更新,歡迎光臨 java開發技術網
          主站蜘蛛池模板: 汶川县| 靖江市| 平舆县| 沧源| 通州区| 志丹县| 双峰县| 崇文区| 福贡县| 黄大仙区| 大新县| 潞西市| 永寿县| 亚东县| 浪卡子县| 兴隆县| 康保县| 墨竹工卡县| 巴林右旗| 鞍山市| 天柱县| 双桥区| 黎川县| 新竹市| 昭苏县| 内乡县| 灵璧县| 邢台县| 宜良县| 香河县| 余干县| 安宁市| 库伦旗| 蓝山县| 陇西县| 望奎县| 遂溪县| 剑阁县| 祥云县| 江津市| 咸丰县|