本站不再更新,歡迎光臨 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 有貓相伴的日子 閱讀(401) 評論(0)  編輯  收藏 所屬分類: Patterns
          本站不再更新,歡迎光臨 java開發技術網
          主站蜘蛛池模板: 天津市| 云林县| 精河县| 武鸣县| 许昌县| 同心县| 西华县| 琼中| 平邑县| 陇川县| 承德市| 从化市| 灵宝市| 年辖:市辖区| 醴陵市| 淳化县| 微博| 和龙市| 迭部县| 鹤庆县| 兴安县| 丰镇市| 奉新县| 虎林市| 荔波县| 仙居县| 双鸭山市| 万年县| 华宁县| 桦甸市| 元江| 连城县| 美姑县| 和顺县| 如东县| 从江县| 九寨沟县| 阿拉善右旗| 南川市| 西昌市| 阿克陶县|