設(shè)計(jì)模式實(shí)驗(yàn)三[共32頁(yè)]
CENTRAL SOUTH UNIVERSITY軟件體系結(jié)構(gòu)實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱 設(shè)計(jì)模式實(shí)驗(yàn)二 學(xué)生姓名 學(xué)生學(xué)號(hào) XXX 專業(yè)班級(jí) 軟件工程1007班 指導(dǎo)教師 劉偉 完成時(shí)間 2012年12月25日 實(shí)驗(yàn)三 設(shè)計(jì)模式實(shí)驗(yàn)二一、實(shí)驗(yàn)?zāi)康氖炀毷褂肞owerDesigner和任意一種面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)幾種常見(jiàn)的設(shè)計(jì)模式,包括外觀模式、代理模式、職責(zé)鏈模式、命令模式、迭代器模式、觀察者模式、策略模式和模板方法模式,理解每一種設(shè)計(jì)模式的模式動(dòng)機(jī),掌握模式結(jié)構(gòu),學(xué)習(xí)如何使用代碼實(shí)現(xiàn)這些模式,并學(xué)會(huì)分析這些模式的使用效果。二、實(shí)驗(yàn)內(nèi)容使用PowerDesigner和任意一種面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)外觀模式、代理模式、職責(zé)鏈模式、命令模式、迭代器模式、觀察者模式、策略模式和模板方法模式,包括根據(jù)實(shí)例繪制模式結(jié)構(gòu)圖、編寫模式實(shí)例實(shí)現(xiàn)代碼,運(yùn)行并測(cè)試模式實(shí)例代碼。(1) 外觀模式某軟件公司為新開(kāi)發(fā)的智能手機(jī)控制與管理軟件提供了一鍵備份功能,通過(guò)該功能可以將原本存儲(chǔ)在手機(jī)中的通信錄、短信、照片、歌曲等資料一次性全部拷貝到移動(dòng)存儲(chǔ)介質(zhì)(例如MMC卡或SD卡)中。在實(shí)現(xiàn)過(guò)程中需要與多個(gè)已有的類進(jìn)行交互,例如通訊錄管理類、短信管理類等,為了降低系統(tǒng)的耦合度,試使用外觀模式來(lái)設(shè)計(jì)并編程模擬實(shí)現(xiàn)該一鍵備份功能。(2) 代理模式在某應(yīng)用軟件中需要記錄業(yè)務(wù)方法的調(diào)用日志,在不修改現(xiàn)有業(yè)務(wù)類的基礎(chǔ)上為每一個(gè)類提供一個(gè)日志記錄代理類,在代理類中輸出日志,如在業(yè)務(wù)方法method()調(diào)用之前輸出“方法method()被調(diào)用,調(diào)用時(shí)間為2010-10-10 10:10:10”,調(diào)用之后如果沒(méi)有拋異常則輸出“方法method()成功調(diào)用”,否則輸出“方法method()調(diào)用失敗”。在代理類中調(diào)用真實(shí)業(yè)務(wù)類的業(yè)務(wù)方法,使用代理模式設(shè)計(jì)該日志記錄功能的結(jié)構(gòu),繪制類圖并編程模擬實(shí)現(xiàn)。(3) 職責(zé)鏈模式某企業(yè)的SCM(Supply Chain Management,供應(yīng)鏈管理)系統(tǒng)中包含一個(gè)采購(gòu)審批子系統(tǒng)。該企業(yè)的采購(gòu)審批是分級(jí)進(jìn)行的,即根據(jù)采購(gòu)金額的不同由不同層次的主管人員來(lái)審批,主任可以審批5萬(wàn)元以下(不包括5萬(wàn)元)的采購(gòu)單,副董事長(zhǎng)可以審批5萬(wàn)元至10萬(wàn)元(不包括10萬(wàn)元)的采購(gòu)單,董事長(zhǎng)可以審批10萬(wàn)元至50萬(wàn)元(不包括50萬(wàn)元)的采購(gòu)單,50萬(wàn)元及以上的采購(gòu)單就需要開(kāi)董事會(huì)討論決定。試使用職責(zé)鏈模式設(shè)計(jì)并實(shí)現(xiàn)該系統(tǒng)。(4) 命令模式某軟件公司欲開(kāi)發(fā)一個(gè)基于Windows平臺(tái)的公告板系統(tǒng)。系統(tǒng)提供一個(gè)主菜單(Menu),在主菜單中包含了一些菜單項(xiàng)(MenuItem),可以通過(guò)Menu類的addMenuItem()方法增加菜單項(xiàng)。菜單項(xiàng)的主要方法是click(),每一個(gè)菜單項(xiàng)包含一個(gè)抽象命令類,具體命令類包括OpenCommand(打開(kāi)命令),CreateCommand(新建命令),EditCommand(編輯命令)等,命令類具有一個(gè)execute()方法,用于調(diào)用公告板系統(tǒng)界面類(BoardScreen)的open()、create()、edit()等方法。試使用命令模式設(shè)計(jì)該系統(tǒng),使得MenuItem類與BoardScreen類的耦合度降低,繪制類圖并編程模擬實(shí)現(xiàn)。(5) 迭代器模式在某在線購(gòu)物系統(tǒng)的購(gòu)物車(Shopping Cart)中包含了一個(gè)存儲(chǔ)商品名稱的字符串?dāng)?shù)組,現(xiàn)需要自定義一個(gè)雙向迭代器(MyIterator)實(shí)現(xiàn)對(duì)該商品名稱數(shù)組的雙向(前向和后向)遍歷。繪制類圖并編程模擬實(shí)現(xiàn)(要求定義抽象層)。(6) 觀察者模式某在線股票軟件需要提供如下功能:當(dāng)股票購(gòu)買者所購(gòu)買的某支股票價(jià)格變化幅度達(dá)到5%時(shí),系統(tǒng)將自動(dòng)發(fā)送通知(包括新價(jià)格)給購(gòu)買該股票的股民?,F(xiàn)使用觀察者模式設(shè)計(jì)該系統(tǒng),繪制類圖并編程模擬實(shí)現(xiàn)(要求定義抽象層)。(7) 策略模式某軟件公司欲開(kāi)發(fā)一款飛機(jī)模擬系統(tǒng),該系統(tǒng)主要模擬不同種類飛機(jī)的飛行特征與起飛特征,需要模擬的飛機(jī)種類及其特征如表1所示:表1 飛機(jī)種類及特征一覽表飛機(jī)種類起飛特征飛行特征直升機(jī)(Helicopter)垂直起飛(VerticalTakeOff)亞音速飛行(SubSonicFly)客機(jī)(AirPlane)長(zhǎng)距離起飛(LongDistanceTakeOff)亞音速飛行(SubSonicFly)殲擊機(jī)(Fighter)長(zhǎng)距離起飛(LongDistanceTakeOff)超音速飛行(SuperSonicFly)鷂式戰(zhàn)斗機(jī)(Harrier)垂直起飛(VerticalTakeOff)超音速飛行(SuperSonicFly)為將來(lái)能夠模擬更多種類的飛機(jī),試采用策略模式設(shè)計(jì)并模擬實(shí)現(xiàn)該飛機(jī)模擬系統(tǒng)。(8) 模板方法模式某軟件公司欲為某銀行的業(yè)務(wù)支撐系統(tǒng)開(kāi)發(fā)一個(gè)利息計(jì)算模塊,利息計(jì)算流程如下:I. 系統(tǒng)根據(jù)賬號(hào)和密碼驗(yàn)證用戶信息,如果用戶信息錯(cuò)誤,系統(tǒng)顯示出錯(cuò)提示;II. 如果用戶信息正確,則根據(jù)用戶類型的不同使用不同的利息計(jì)算公式計(jì)算利息(如活期賬戶和定期賬戶具有不同的利息計(jì)算公式);III. 系統(tǒng)顯示利息。試使用模板方法模式設(shè)計(jì)并模擬實(shí)現(xiàn)該利息計(jì)算模塊。三、實(shí)驗(yàn)要求1. 正確無(wú)誤繪制外觀模式、代理模式、職責(zé)鏈模式、命令模式、迭代器模式、觀察者模式、策略模式和模板方法模式實(shí)例的模式結(jié)構(gòu)圖;2. 使用任意一種面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)外觀模式、代理模式、職責(zé)鏈模式、命令模式、迭代器模式、觀察者模式、策略模式和模板方法模式實(shí)例,代碼運(yùn)行正確無(wú)誤。四、實(shí)驗(yàn)步驟1. 進(jìn)一步熟悉PowerDesigner15的常用功能;2. 使用PowerDesigner繪制外觀模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;3. 使用PowerDesigner繪制代理模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;4. 使用PowerDesigner繪制職責(zé)鏈模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;5. 使用PowerDesigner繪制命令模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;6. 使用PowerDesigner繪制迭代器模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;7. 使用PowerDesigner繪制觀察者模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;8. 使用PowerDesigner繪制策略模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例;9. 使用PowerDesigner繪制模板方法模式實(shí)例結(jié)構(gòu)圖并用面向?qū)ο缶幊陶Z(yǔ)言實(shí)現(xiàn)該模式實(shí)例。五、實(shí)驗(yàn)報(bào)告要求1. 提供外觀模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;2. 提供代理模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;3. 提供職責(zé)鏈模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;4. 提供命令模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;5. 提供迭代器模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;6. 提供觀察者模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;7. 提供策略模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;8. 提供模板方法模式實(shí)例結(jié)構(gòu)圖及實(shí)現(xiàn)代碼;9. 注意調(diào)整類圖中文字的字體及字號(hào),注意圖的整體布局和圖的大小,避免使用交叉線,注意代碼字體和顏色,代碼字體需一致,顏色需統(tǒng)一;10. 認(rèn)真寫好實(shí)驗(yàn)總結(jié);11. 提交電子版實(shí)驗(yàn)報(bào)告,格式為“學(xué)號(hào)-姓名-實(shí)驗(yàn)3.doc”,如“060102-張三-實(shí)驗(yàn)3.doc”,所有材料(包括類圖和源代碼)均放在一個(gè)Word文件中,格式為doc或docx,不需要提交PowerDeigner所保存的oom模型,也無(wú)須單獨(dú)提交源代碼。六、實(shí)驗(yàn)結(jié)果1. 類圖:實(shí)現(xiàn)代碼:Client.javapackage dm.facade;public class Client public static void main(String args) BackupFacade bf = new BackupFacade();bf.oneKeyBackup();BackupFacade.javapackage dm.facade;public class BackupFacade private SmsManager sms;private SongsManager song;private ContactManager contact;private PhotoManager photo;public BackupFacade() sms = new SmsManager();song = new SongsManager();contact = new ContactManager();photo = new PhotoManager();public void oneKeyBackup() sms.oneKeyBackup();song.oneKeyBackup();contact.oneKeyBackup();photo.oneKeyBackup();SmsManager.javapackage dm.facade;public class SmsManager public void oneKeyBackup() System.out.println("Sms Backup Over");SongsManager.javapackage dm.facade;public class SongsManager public void oneKeyBackup() System.out.println("Songs Backup Over");PhotoManager.javapackage dm.facade;public class PhotoManager public void oneKeyBackup() / TODO: implement System.out.println("Photo Backup Over"); ContactManager.javapackage dm.facade;public class ContactManager public void oneKeyBackup() System.out.println("Contact Backup Over");2. 類圖:實(shí)現(xiàn)代碼:Client.javapackage dm.proxy;public class Client public static void main(String args) Service service;service = new Proxy();service.method();Proxy.javapackage dm.proxy;public class Proxy implements Service private RealService service = new RealService();public void method() service.method();Service.javapackage dm.proxy;public interface Service void method();RealService.javapackage dm.proxy;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Random;public class RealService implements Service public void method() try Date date = new Date();/ format對(duì)象是用來(lái)以指定的時(shí)間格式格式化時(shí)間的SimpleDateFormat from = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); / 這里的格式可以自己設(shè)置/ format()方法是用來(lái)格式化時(shí)間的方法String times = from.format(date);System.out.println("方法method()被調(diào)用,調(diào)用時(shí)間為:" + times); /用來(lái)產(chǎn)生除零異常來(lái)模擬method方法調(diào)用是否成功Random random = new Random();int a = random.nextInt(100);int b = random.nextInt(10);SuppressWarnings("unused")int c = a/b;System.out.println("方法method()成功調(diào)用"); catch (Exception e) / TODO: handle exceptionSystem.out.println("方法method()調(diào)用失敗");3. 類圖:實(shí)現(xiàn)代碼:Client.javapackage dm.chainofresponsibility;public class Client public static void main(String args) Leader objDirector, objDepartmentManager, objGeneralManager;objDirector = new Director("張三");objDepartmentManager = new Manager("李四");objGeneralManager = new GeneralManager("王五");objDirector.setSuccessor(objDepartmentManager);objDepartmentManager.setSuccessor(objGeneralManager);System.out.println("-");PurchaseRequest shopping1 = new PurchaseRequest(10000.00, "購(gòu)買打印紙");objDirector.handleRequest(shopping1);System.out.println("-");PurchaseRequest shopping2 = new PurchaseRequest(80000.00, "辦公室配置空調(diào)");objDirector.handleRequest(shopping2);System.out.println("-");PurchaseRequest shopping3 = new PurchaseRequest(150000.00, "車間維修");objDirector.handleRequest(shopping3);System.out.println("-");PurchaseRequest shopping4 = new PurchaseRequest(10000000.00, "收購(gòu)RL公司");objDirector.handleRequest(shopping4);System.out.println("-");PurchaseRequest.javapackage dm.chainofresponsibility;public class PurchaseRequest private double billMoney;private String reason;public PurchaseRequest(double billMoney, String reason) this.billMoney = billMoney;this.reason = reason;public double getBillMoney() return billMoney;public void setBillMoney(double billMoney) this.billMoney = billMoney;public String getReason() return reason;public void setReason(String reason) this.reason = reason;Leader.javapackage dm.chainofresponsibility;public abstract class Leader protected String name;protected Leader successor;public void setSuccessor(Leader seccessor) this.successor = seccessor;public Leader(String name) this.name = name;public abstract void handleRequest(PurchaseRequest request);Manager.javapackage dm.chainofresponsibility;public class Manager extends Leader public Manager(String name) super(name);public void handleRequest(PurchaseRequest request) if (request.getBillMoney() < 100000.00) System.out.println("總經(jīng)理" + name + "處理物資采購(gòu):" + request.getReason()+ ",批準(zhǔn)采購(gòu)資金為:" + request.getBillMoney() + "RMB"); else if (this.successor != null) this.successor.handleRequest(request);GeneralManager.javapackage dm.chainofresponsibility;public class GeneralManager extends Leader public GeneralManager(String name) super(name);public void handleRequest(PurchaseRequest request) if (request.getBillMoney() < 500000.00) System.out.println("總經(jīng)理" + name + "處理物資采購(gòu):" + request.getReason()+ ",批準(zhǔn)采購(gòu)資金為:" + request.getBillMoney() + "RMB"); else System.out.println("董事會(huì)將開(kāi)會(huì)處理物資采購(gòu):" + request.getReason()+ ",批準(zhǔn)采購(gòu)資金為:" + request.getBillMoney() + "RMB");Director.javapackage dm.chainofresponsibility;public class Director extends Leader public Director(String name) super(name);public void handleRequest(PurchaseRequest request) if (request.getBillMoney() < 50000.00) System.out.println("主任" + name + "處理物資采購(gòu):" + request.getReason()+ ",批準(zhǔn)采購(gòu)資金為:" + request.getBillMoney() + "RMB"); else if (this.successor != null) this.successor.handleRequest(request);4. 類圖:實(shí)現(xiàn)代碼:Client.javapackage mand;public class Client public static void main(String args) BoardScreen screen = new BoardScreen();Menu menu = new Menu();MenuItem open = new MenuItem("open", new OpenCommand(screen);MenuItem create = new MenuItem("create", new CreateCommand(screen);MenuItem edit = new MenuItem("edit", new EditCommand(screen);menu.addMenuItem(open);menu.addMenuItem(create);menu.addMenuItem(edit);menu.getMenuItemByName("open").click();menu.getMenuItemByName("create").click();menu.getMenuItemByName("edit").click();Menu.javapackage mand;import java.util.*;public class Menu private ArrayList<MenuItem> menuItemList = new ArrayList<MenuItem>();public void addMenuItem(MenuItem item) / TODO: implementthis.menuItemList.add(item);public MenuItem getMenuItemByName(String itemName) / TODO: implementfor (int i = 0; i < menuItemList.size(); i+) if (menuItemList.get(i).getItemName().equals(itemName) return menuItemList.get(i);return null;MenuItem.javapackage mand;public class MenuItem private String itemName;private Command command;public void click() / TODO: implementSystem.out.println("MenuItem " + this.itemName + " clicked!");mand.execute();public MenuItem(String name, Command cmd) / TODO: implementmand = cmd;this.itemName = name;public String getItemName() return itemName;public void setItemName(String newItemName) itemName = newItemName;public Command getCommand() return command;public void setCommand(Command newCommand) mand = newCommand;Command.javapackage mand;public interface Command void execute();CreateCommand.javapackage mand;public class CreateCommand implements Command private BoardScreen myBoardScreen;public CreateCommand(BoardScreen myBoardScreen) this.myBoardScreen = myBoardScreen;public void execute() / TODO: implementmyBoardScreen.create();EditCommand.javapackage mand;public class EditCommand implements Command private BoardScreen myBoardScreen;public EditCommand(BoardScreen myBoardScreen)this.myBoardScreen = myBoardScreen;public void execute() / TODO: implementmyBoardScreen.edit();OpenCommand.javapackage mand;public class OpenCommand implements Command private BoardScreen myBoardScreen;public OpenCommand(BoardScreen myBoardScreen) this.myBoardScreen = myBoardScreen;public void execute() / TODO: implementmyBoardScreen.open();BoardScreen.javapackage mand;public class BoardScreen public void open() / TODO: implementSystem.out.println("BoardScreen opened!");public void create() / TODO: implementSystem.out.println("BoardScreen create!");public void edit() / TODO: implementSystem.out.println("BoardScreen edit!");5. 類圖:實(shí)現(xiàn)代碼:Client.javapackage dm.iterator;public class Client public static void main(String args) MyCollection collection = new NewCollection();MyIterator i = collection.createIterator();System.out.println("正向遍歷-");i.first();System.out.print(i.getCurrentItem().toString() + " ");while (i.hasNext() i.next();System.out.print(i.getCurrentItem().toString() + " ");System.out.println("n逆向遍歷-");i.last();System.out.print(i.getCurrentItem().toString() + " ");while (i.hasPrevious() i.previous();System.out.print(i.getCurrentItem().toString() + " ");System.out.println();MyIterator.javapackage dm.iterator;public interface MyIterator void first();void last();boolean hasNext();boolean hasPrevious();void next();void previous();boolean isFirst();boolean isLast();Object getCurrentItem();MyCollection.javapackage dm.iterator;public interface MyCollection MyIterator createIterator();NewCollection.javapackage dm.iterator;public class NewCollection implements MyCollection private Object obj = "I", "P", "h", "o", "n", "e" ;public MyIterator createIterator() / TODO: implementreturn new NewIterator();/ 內(nèi)部類迭代器public class NewIterator implements MyIterator private int currentIndex = 0;public void first() / TODO: implementcurrentIndex = 0;public void last() / TODO: implementcurrentIndex = obj.length - 1;public boolean hasNext() / TODO: implementif (currentIndex < obj.length - 1) return true;return false;public boolean hasPrevious() / TODO: implementif (currentIndex > 0) return true;return false;public void next() / TODO: implementif (currentIndex < obj.length) currentIndex+;public void previous() / TODO: implementif (currentIndex > 0) currentIndex-;public boolean isFirst() / TODO: implementreturn currentIndex = 0;public boolean isLast() / TODO: implementreturn currentIndex = obj.length - 1;public Object getCurrentItem() / TODO: implementreturn objcurrentIndex;6. 類圖:實(shí)現(xiàn)代碼:Client.javapackage dm.observer;public class Client public static void main(String args) / TODO Auto-generated method stubStock stock = new Stock(1000.0);new Stocker("zhangsan", stock);new Stocker("lisi", stock);stock.setPrice(1234.0);stock.setPrice(1234.5);stock.setPrice(999.9);stock.setPrice(1111.1);Observer.javapackage dm.observer;public interface Observer void response();Subject.javapackage dm.observer;import java.util.*;public abstract class Subject private Vector<Observer> vector = new Vector<Observer>();public void addObserver(Observer observer) / TODO: implementthis.vector.add(observer);public void deleteObserver(Observer observer) / TODO: implementthis.vector.remove(observer);public void fireNotice() for(int i=0;i<vector.size();i+)(Observer)vector.elementAt(i).response(); Stock.javapackage dm.observer;public class Stock extends Subject private double price;public Stock(double price) / TODO Auto-generated constructor stubthis.price = price;public double getPrice() return price;public void setPrice(double newPrice) double change = this.price - newPrice;price = newPrice;if (change / this.price > 0.05 | change / this.price < -0.05) super.fireNotice();Stocker.javapackage dm.observer;public class Stocker implements Observer private String name;private Stock subject;public Stock stock;public Stocker(String name, Stock subject) / TODO: implementthis.name = name;this.subject = subject;subject.addObserver(this);public void response() / TODO: implementSystem.out.println("股民 " + name + " 被通知股票發(fā)生了變化,新價(jià)格為:"+ subject.getPrice();7. 類圖:實(shí)現(xiàn)代碼:Client.javapackage dm.strategy;public class Client public static void main(String args) / TODO Auto-generated method stubFlyBehavior flyBehavior;flyBehavior = new SubSonicFly();TakeOffBehavior takeOffBehavior;takeOffBehavior = new VerticalTakeOff();new Helicopter(flyBehavior, takeOffBehavior);System.out.println("-");flyBehavior = new SubSonicFly();takeOffBehavior = new LongDistanceTakeOff();new AirPlane(flyBehavior, takeOffBehavior);System.out.println("-");flyBehavior = new SuperSonicFly();takeOffBehavior = new LongDistanceTakeOff();new Fighter(flyBehavior, takeOffBehavior);System.out.println("-");flyBehavior = new SuperSonicFly();takeOffBehavior = new VerticalTakeOff();new Harrier(flyBehavior, takeOffBehavior);AirCraft.javapackage dm.strategy;public class AirCraft private FlyBehavior flyBehavior;private TakeOffBehavior takeOffBehavior;public AirCraft(FlyBehavior flyBehavior, TakeOffBehavior takeOffBehavior) this.flyBehavior = flyBehavior;this.takeOffBehavior = takeOffBehavior;public FlyBehavior getFlyBehavior() return flyBehavior;public void setFlyBehavior(FlyBehavior flyBehavior) this.flyBehavior = flyBehavior;public TakeOffBehavior getTakeOffBehavior() return takeOffBehavior;public void setTakeOffBehavior(TakeOffBehavior takeOffBehavior) this.takeOffBehavior = takeOffBehavior;FlyBehavior.javapackage dm.strategy;public class FlyBehavior public void fly() / TODO: implementSystem.out.println("飛機(jī)飛行");TakeOffBehavior.javapackage dm.strategy;public class TakeOffBehavior public void takeOff() / TODO: implementSystem.out.println("飛機(jī)起飛");VerticalTakeOff.javapackage dm.strategy;public class VerticalTakeOff extends TakeOffBehavior public void takeOff() / TODO: implementSystem.out.println("垂直起飛(VerticalTakeOff)");SubSonicFly.javapackage dm.strategy;public class SubSonicFly extends FlyBehavior public void fly() / TODO: implementSystem.out.println("亞音速飛行(SubSonicFly)");LongDistanceTakeOff.javapackage dm.strategy;public class LongDistanceTakeOff extends TakeOffBehavior public void takeOff() / TODO: implementSystem.out.println("長(zhǎng)距離起飛(LongDistanceTakeOff)");SuperSonicFly.javapackage dm.strategy;public class SuperSonicFly extends FlyBehavior public void fly() / TODO: implementSystem.out.println("超音速飛行(SuperSonicFly)");AirPlane.javapackage dm.strategy;public class AirPlane extends AirCraft public AirPlane(FlyBehavior flyBehavior, TakeOffBehavior takeOffBehavior) super(flyBehavior, takeOffBehavior);System.out.println("客機(jī)(AirPlane)");flyBehavior.fly();takeOffBehavior.tak