第10章UML與設計模式_第1頁
第10章UML與設計模式_第2頁
第10章UML與設計模式_第3頁
第10章UML與設計模式_第4頁
第10章UML與設計模式_第5頁
已閱讀5頁,還剩75頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、1UML與設計模式與設計模式2什么是設計模式什么是設計模式 定義:設計模式是從許多優(yōu)秀的軟件系統(tǒng)中總結出成功的可復用的設計方案. 簡單地說:設計模式是對某特定環(huán)境下某類問題的解決方法。3說明: 設計模式是可重用的設計經(jīng)驗的總結,已在實際的系統(tǒng)中多次得到成功應用。 設計模式一般是針對用面向對象技術的。 設計模式不只是關于孤立的對象的設計,還強調(diào)對象之間的通信。 設計模式突出了OO設計中的封裝、泛化、多態(tài)等概念,學習設計模式,必須清楚這些概念的使用。 設計模式通常都很小,只涉及幾個類。4設計模式的歷史設計模式的歷史 設計模式設計模式的概念最早是由建筑師克里斯托夫亞歷山大(Christopher A

2、lexander)提出來的(70年代后期)。 Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. 模式語言(A Pattern Langua

3、ge) Erich Gamma博士論文(1991)的部分工作 開始對設計模式進行分類整理5 E. Gamma, R. Helm, R. Johnson, and J. Vlissides 等四人合著的“Design Patterns: Elements of Object-Oriented Software” Addison-Wesley, 1995 The Gang of Four(GoF) patterns 書的中、英文電子版在ftp上 理解設計模式已成為任何面向對象軟件開發(fā)人員所必需具備的重要素質之一。6 Design Patterns Elements of Reusable Obje

4、ct-Oriented Software 作者E.GammaR. Helm, R. JohnsonJ. Vlissides四位作者通常被稱為四人組(Gang of Four, 或GoF) 7使用設計模式的好處使用設計模式的好處1. Simplify and speed-up design(簡化和加快了設計) 無需從底層做起,從設計模式入手可以節(jié)省時間,提高開發(fā)質量。2. Facilitate communications between designers (方便了設計者之間的通信) 更準確地描述問題和它們的解決方案,使解決方案具有一致性,使代碼更容易理解。 開發(fā)人員可以在更高的層次上來思考問

5、題和討論方案。例:“建議用Visitor模式來解決這個問題”3. Reduce risk(降低風險)4. Patterns help ease the transition to object-oriented technology.(有助于轉到OO技術)8設計模式的分類設計模式的分類 GoF中共有23個設計模式,這些模式可以按兩個準則來分類:1. 按設計模式的按設計模式的purpose來分類來分類:分為創(chuàng)建型模式,結構型模式和行為型模式三種。2. 按設計模式的按設計模式的scope來劃分來劃分:即根據(jù)設計模式是作用于類還是作用于對象,把設計模式分為類設計模式和對象設計模式。9Purpose對

6、象創(chuàng)建型結構型行為型類ScopeFactory MethodAbstract FactoryBuilderPrototypeSingletonAdapterAdapterBridgeCompositeDecoratorFacadeFlyweightProxyInterpreterTemplate MethodChain of ResponsibilityCommandIteratorMediatorMementoObserverStateStrategyVisitor設計模式的分類表:設計模式的分類表:10創(chuàng)建型模式創(chuàng)建型模式 創(chuàng)建型模式創(chuàng)建型模式(Creational pattern):Cr

7、eational design patterns abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented. 創(chuàng)建型模式創(chuàng)建型模式抽象了實例化過程。它們幫助一個系統(tǒng)獨立于如何創(chuàng)建、組合和表示它的那些對象。 創(chuàng)建型模式包括: Factory Method(工廠方法) Abstract Factory(抽象工廠) Builder(生成器) Prototype(原型) Singleton(單件)11結

8、構型模式結構型模式 結構型模式結構型模式(Structural pattern):Structural patterns are concerned with how classes and objects are composed to form larger structures. 結構型模式結構型模式涉及到如何組合類和對象以獲得更大的結構。 結構型模式包括: Adapter(適配器) Bridge(橋接) Composite(組成) Decorator(裝飾) Facade(外觀) Flyweight(享元) Proxy(代理)12行為型模式行為型模式 行為型模式行為型模式(behavi

9、oral pattern):Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects. Behavioral patterns describe not just patterns of objects or classes but also the patterns of communication between them. 行為型模式行為型模式涉及到算法和對象間職責的分配。行為型模式行為型模式不僅描述對象或類的模式,還描述它們之間的通信模

10、式。13 行為型模式包括: Chain of Responsibility(職責鏈) Command(命令) Interpreter(解釋器) Iterator(迭代器) Mediator(中介者) Memento(備忘錄) Observer(觀察者) State(狀態(tài)) Strategy(策略) Template method(模板方法) Visitor(訪問者)14記錄一個設計模式需要有四個基本要素:1.名稱 高度概括該模式的本質,有利于該行業(yè)統(tǒng)一術語、便于交流使用2.問題 描述應該在何時使用模式,解釋設計問題和問題存在的前因后果3.方案 描述設計的組成部分,它們之間的相互關系及各自的職責

11、和協(xié)作方式4.效果 使用模式對系統(tǒng)的靈活性、擴充性和復用性的影響15例:中介者模式 名稱 中介者 問題 用一個中介者來封閉一系列的對象 交互 方案 中介者接口、具體中介者、同事、具體同事 效果 減少了子類的生成,將各個同事解耦,簡化了對象協(xié)議,控制集中化16設計模式中使用的兩個設計模式中使用的兩個OO設計原則設計原則1. Program to an interface and not to an implementation. (針對接口編程,而不是針對實現(xiàn)編程)2. Favor object composition over inheritance. (優(yōu)先使用對象組合,而不是使用繼承)17

12、主要內(nèi)容主要內(nèi)容 基本概念基本概念 設計模式實例分析設計模式實例分析 18Facade設計模式設計模式 Facade設計模式設計模式屬于對象結構型設計模式。 intent:Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. 為子系統(tǒng)中的一組接口提供一個一致的界面, Facade模式定義了一個高層接口,這個接口使得這一子系統(tǒng)更加容易使用。19外觀模式外觀模式

13、 外觀模式外觀模式為系統(tǒng)中的一組接口提供一個一致的界面,為系統(tǒng)中的一組接口提供一個一致的界面,F(xiàn)aade模式模式定義了一個高層接口,這個接口使得這一子系統(tǒng)更加容定義了一個高層接口,這個接口使得這一子系統(tǒng)更加容易使用。易使用。Chain of Responsibility Pattern Provide a unified interface to a set of interfaces in a subsystem.Facade defines a higher-level interface that makes the subsystem easier to use.20子系統(tǒng)的客戶端 使

14、用一個子系統(tǒng)的客戶端往往只關注一些特定的功能,需要同時與子系統(tǒng)內(nèi)部的許多對象打交道后才能達到目的。21醫(yī)院的例子22醫(yī)院的解決方案23概述概述 2022-6-27 外觀模式是簡化用戶和子系統(tǒng)進行交外觀模式是簡化用戶和子系統(tǒng)進行交互的成熟模式,外觀模式的關鍵是為子互的成熟模式,外觀模式的關鍵是為子系統(tǒng)提供一個稱作外觀的類,該外觀類系統(tǒng)提供一個稱作外觀的類,該外觀類的實例負責和子系統(tǒng)中類的實例打交道。的實例負責和子系統(tǒng)中類的實例打交道。當用戶想要和子系統(tǒng)中的若干個類的實當用戶想要和子系統(tǒng)中的若干個類的實例打交道時,可以代替地和子系統(tǒng)的外例打交道時,可以代替地和子系統(tǒng)的外觀類的實例打交道。觀類的實例

15、打交道。 24應用實例應用實例 2022-6-2724 郵政系統(tǒng)負責郵寄包裹的子系統(tǒng)包含郵政系統(tǒng)負責郵寄包裹的子系統(tǒng)包含CheckCheck、WeightWeight和和TransportTransport類。類。CheckCheck類類的實例負責對包裹進行安全檢查,的實例負責對包裹進行安全檢查,WeightWeight類的實例負責根據(jù)包裹的重量計類的實例負責根據(jù)包裹的重量計算郵資,算郵資,TransportTransport類的實例負責為包裹類的實例負責為包裹選擇運輸工具。一個要郵寄的包裹的用選擇運輸工具。一個要郵寄的包裹的用戶如果直接和負責郵寄包裹的子系統(tǒng)的戶如果直接和負責郵寄包裹的子系統(tǒng)

16、的類打交道就會非常不方便。類打交道就會非常不方便。 25 引入Facade對象后Client和子系統(tǒng)之間通信關系的變化:client classessubsystem classes26說明: Client通過調(diào)用Facade中的方法來和子系統(tǒng)通信。 Client很少直接存取子系統(tǒng)中的對象。 子系統(tǒng)中的對象不需要了解關于Client的知識。 子系統(tǒng)中對象不需要了解關于Facade對象的知識,即沒有指向Facade的引用。 引入Facade對象可以降低Client和子系統(tǒng)之間相互依賴關系,降低系統(tǒng)的耦合度,增加了系統(tǒng)的靈活性。27 Facade設計模式中的參與者(Participant)為Fac

17、ade和 subsystem classes :1. Facade: 知道哪些子系統(tǒng)類負責處理請求 將客戶請求代理給適當子系統(tǒng)對象 2. subsystem classes 實現(xiàn)子系統(tǒng)功能. 處理Faade對象指派的任務 子類中沒有Faade的任何信息,即無對Faade對象的引用。28應用實例應用實例 2022-6-2728 報社的廣告系統(tǒng)有三個類報社的廣告系統(tǒng)有三個類CheckWordCheckWord、ChargeCharge和和TypeSettingTypeSetting類,各個類的職責類,各個類的職責如下:如下:CheckWordCheckWord類負責檢查廣告內(nèi)容含類負責檢查廣告內(nèi)容

18、含有的字符數(shù)量;有的字符數(shù)量;ChargeCharge類的實例負責計類的實例負責計算費用;算費用;TypeSettingTypeSetting的實例負責對廣告的實例負責對廣告進行排版。使用外觀模式簡化用戶和上進行排版。使用外觀模式簡化用戶和上述子系統(tǒng)所進行的交互。述子系統(tǒng)所進行的交互。292022-6-2729模式的結構的描述與使用模式的結構的描述與使用 1 1子系統(tǒng)(子系統(tǒng)(SubsystemSubsystem)_1_1 : : CheckWord.javaCheckWord.java public class CheckWordpublic class CheckWord public f

19、inal int basicAmount public final int basicAmount=85;=85; String advertisement; String advertisement; int int amount; amount; public CheckWord(String public CheckWord(String advertisement) advertisement) this.advertisement=advertisement; this.advertisement=advertisement; public void setChargeAmount

20、public void setChargeAmount() () amount=advertisement.length()+basicAmount amount=advertisement.length()+basicAmount; /; /計算出計費字符數(shù)目計算出計費字符數(shù)目 public int getAmount public int getAmount()() return amount; return amount; 302022-6-2730模式的結構的描述與使用模式的結構的描述與使用 1 1子系統(tǒng)(子系統(tǒng)(SubsystemSubsystem)_2_2 : : Charge.j

21、ava Charge.java public class Chargepublic class Charge public final int basicCharge public final int basicCharge=12;=12; CheckWord checkWord CheckWord checkWord; ; Charge(CheckWord checkWord Charge(CheckWord checkWord) this.checkWord=checkWord this.checkWord=checkWord; ; public void giveCharge publi

22、c void giveCharge()() int charge=checkWord.getAmount() int charge=checkWord.getAmount()* *basicChargebasicCharge; ; System.out.println System.out.println(廣告費用廣告費用:+charge+:+charge+元元);); 312022-6-2731模式的結構的描述與使用模式的結構的描述與使用 1 1子系統(tǒng)(子系統(tǒng)(SubsystemSubsystem)_3_3 : :TypeSeting.javaTypeSeting.java public c

23、lass TypeSetingpublic class TypeSeting String advertisement; String advertisement; public TypeSeting(String public TypeSeting(String advertisement) advertisement) this.advertisement=advertisement; this.advertisement=advertisement; public void typeSeting public void typeSeting() () System.out.println

24、 System.out.println(廣告排版格式廣告排版格式:);:); System.out.println System.out.println(* * * * * * * * *);); System.out.println(advertisement System.out.println(advertisement);); System.out.println System.out.println(* * * * * * * * *); ); 322022-6-2732模式的結構的描述與使用模式的結構的描述與使用 2 2外觀(外觀(FacadeFacade): : ClientSe

25、rverFacade.javaClientServerFacade.java public class ClientServerFacadepublic class ClientServerFacade private CheckWord checkWord private CheckWord checkWord; ; private Charge charge; private Charge charge; private TypeSeting typeSeting private TypeSeting typeSeting; ; String advertisement; String a

26、dvertisement; public ClientServerFacade(String public ClientServerFacade(String advertisement) advertisement) this.advertisement=advertisement; this.advertisement=advertisement; checkWord=new CheckWord(advertisement checkWord=new CheckWord(advertisement);); charge=new Charge(checkWord charge=new Cha

27、rge(checkWord);); typeSeting=new TypeSeting(advertisement typeSeting=new TypeSeting(advertisement); ); public void doAdvertisement public void doAdvertisement() () checkWord.setChargeAmount checkWord.setChargeAmount();(); charge.giveCharge charge.giveCharge();(); typeSeting.typeSeting typeSeting.typ

28、eSeting();(); 332022-6-2733模式的結構的描述與使用模式的結構的描述與使用 3 3應用應用 Application.javaApplication.java public class Applicationpublic class Application public static void main(String args public static void main(String args) ClientServerFacade clientFacade ClientServerFacade clientFacade; ; String clientAdverti

29、sement String clientAdvertisement=鹿花牌洗衣機,價格鹿花牌洗衣機,價格23562356元,聯(lián)系電話:元,聯(lián)系電話:1234567;1234567; clientFacade=new ClientServerFacade(clientAdvertisement clientFacade=new ClientServerFacade(clientAdvertisement);); clientFacade.doAdvertisement clientFacade.doAdvertisement();(); 34Facade設計模式的適用場合設計模式的適用場合 在下

30、列情況下,可考慮使用Facade設計模式: want to provide a simple interface to a complex subsystem. there are many dependencies between clients and the implementation classes of an abstraction. want to layer your subsystems. 35外觀模式的優(yōu)點外觀模式的優(yōu)點 2022-6-2735使客戶和子系統(tǒng)中的類無耦合。使客戶和子系統(tǒng)中的類無耦合。外觀只是提供了一個更加簡潔的界面,并不影外觀只是提供了一個更加簡潔的界面,并

31、不影響用戶直接使用子系統(tǒng)中的類。響用戶直接使用子系統(tǒng)中的類。子系統(tǒng)中任何類對其方法的內(nèi)容進行修改,不子系統(tǒng)中任何類對其方法的內(nèi)容進行修改,不影響外觀的代碼。影響外觀的代碼。36解析文件思考設計一個子系統(tǒng),該子系統(tǒng)中有三個類: ReadFile類的實例可以讀取文本文件 AnalyzeInformation類的實例可以從一個文本中刪除用戶不需要的內(nèi)容 SaveFile類的實例能將一個文本保存到文本文件請為上述子系統(tǒng)設計一個外觀,以便簡化用戶和上述子系統(tǒng)所進行的交互。37Abstract Factory設計模式設計模式 Abstract factory屬于對象創(chuàng)建型設計模式。 提供一個創(chuàng)建一系列相關

32、或相互依賴對象的接口,而無需指定它們具體的類。38Abstract Factory的適用場合的適用場合 在下列情況下,可考慮使用Abstract Factory設計模式: A system should be independent of how its products are created, composed, and represented. A system should be configured with one of multiple families of products. A family of related product objects is designed to

33、 be used together, and you need to enforce this constraint. You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations. 3940Abstract Factory的一般結構的一般結構41說明: Abstract Factory設計模式中的參與者為 AbstractFactory ConcreteFactory AbstractProduct Concret

34、eProduct Client 客戶類僅使用由AbstractFactory和AbstractProduct 聲明的接口。42Abstract Factory設計模式的特點設計模式的特點1. Client只通過product接口操作product對象,product對象的具體名字不出現(xiàn)在client中。2. 在應用系統(tǒng)中改變ConcreteFactory的種類很容易。3. 可以保證應用系統(tǒng)在某一時刻只使用一個product系列。4. AbstractFactory接口中已確定了可以創(chuàng)建的product集合,如果要支持新的產(chǎn)品種類需要擴展AbstractFactory及其所有子類中的方法,比較困

35、難。43一一 、 一個實例一個實例 2022-6-2743 建立一個系統(tǒng),該系統(tǒng)可以為用戶提供西服套建立一個系統(tǒng),該系統(tǒng)可以為用戶提供西服套裝(上衣褲子)和牛仔套裝(上衣褲子)。裝(上衣褲子)和牛仔套裝(上衣褲子)。442022-6-2744模式的結構的描述與使用模式的結構的描述與使用 1 1抽象產(chǎn)品(抽象產(chǎn)品(ProductProduct) : :UpperClothes.javaUpperClothes.javapublic abstract class UpperClothespublic abstract class UpperClothes public abstract int g

36、etChestSize public abstract int getChestSize();(); public abstract int getHeight public abstract int getHeight();(); public abstract String getName public abstract String getName(); (); Trousers.javaTrousers.javapublic abstract class Trouserspublic abstract class Trousers public abstract int getWais

37、tSize public abstract int getWaistSize();(); public abstract int getHeight public abstract int getHeight();(); public abstract String getName public abstract String getName(); (); 452022-6-2745模式的結構的描述與使用模式的結構的描述與使用 2 2具體產(chǎn)品(具體產(chǎn)品(ConcreteProduct)_1: ConcreteProduct)_1: WesternUpperClothes.javaWestern

38、UpperClothes.java public class WesternUpperClothes extends UpperClothespublic class WesternUpperClothes extends UpperClothes private int chestSize private int chestSize; ; private int private int height; height; private String name; private String name; WesternUpperClothes(String name,int chestSize,

39、int WesternUpperClothes(String name,int chestSize,int height) height) =name; =name; this.chestSize=chestSize this.chestSize=chestSize; ; this.height=height; this.height=height; public int getChestSize public int getChestSize()() return chestSize return chestSize; ; public int getHe

40、ight public int getHeight()() return height; return height; public String getName public String getName()() return name; return name; 462022-6-2746模式的結構的描述與使用模式的結構的描述與使用 2 2具體產(chǎn)品(具體產(chǎn)品(ConcreteProduct)_2: ConcreteProduct)_2: CowboyUpperClothes.javaCowboyUpperClothes.java public class CowboyUpperClothe

41、s extends UpperClothespublic class CowboyUpperClothes extends UpperClothes private int chestSize private int chestSize; ; private int private int height; height; private String name; private String name; CowboyUpperClothes(String name,int chestSize,int CowboyUpperClothes(String name,int chestSize,in

42、t height) height) =name; =name; this.chestSize=chestSize this.chestSize=chestSize; ; this.height=height; this.height=height; public int getChestSize public int getChestSize()() return chestSize return chestSize; ; public int getHeight public int getHeight()() return height; return

43、height; public String getName public String getName()() return name; return name; 472022-6-2747模式的結構的描述與使用模式的結構的描述與使用 2 2具體產(chǎn)品(具體產(chǎn)品(ConcreteProduct)_3: ConcreteProduct)_3: WesternTrousers.javaWesternTrousers.java public class WesternTrouserspublic class WesternTrousers extends Trousers extends Trouse

44、rs private int waistSize private int waistSize; ; private int private int height; height; private String name; private String name; WesternTrousers(String name,int waistSize,int WesternTrousers(String name,int waistSize,int height) height) =name; =name; this.waistSize=waistSize thi

45、s.waistSize=waistSize; ; this.height=height; this.height=height; public int getWaistSize public int getWaistSize()() return waistSize return waistSize; ; public int getHeight public int getHeight()() return height; return height; public String getName public String getName()() return name; return na

46、me; 482022-6-2748模式的結構的描述與使用模式的結構的描述與使用 2 2具體產(chǎn)品(具體產(chǎn)品(ConcreteProduct)_4: ConcreteProduct)_4: CowboyTrousers.javaCowboyTrousers.java public class CowboyTrouserspublic class CowboyTrousers extends Trousers extends Trousers private int waistSize private int waistSize; ; private int private int height;

47、height; private String name; private String name; CowboyTrousers(String name,int waistSize,int CowboyTrousers(String name,int waistSize,int height) height) =name; =name; this.waistSize=waistSize this.waistSize=waistSize; ; this.height=height; this.height=height; public int getWaist

48、Size public int getWaistSize()() return waistSize return waistSize; ; public int getHeight public int getHeight()() return height; return height; public String getName public String getName()() return name; return name; 492022-6-2749模式的結構的描述與使用模式的結構的描述與使用 3 3抽象工廠(抽象工廠(AbstractFactoryAbstractFactory)

49、: :ClothesFactory.javaClothesFactory.java public abstract class ClothesFactorypublic abstract class ClothesFactory public abstract UpperClothes createUpperClothes(int chestSize,int public abstract UpperClothes createUpperClothes(int chestSize,int height); height); public abstract Trousers createTrou

50、sers(int waistSize,int public abstract Trousers createTrousers(int waistSize,int height); height); 502022-6-2750模式的結構的描述與使用模式的結構的描述與使用 4 4具體工廠(具體工廠(ConcreteFactoryConcreteFactory): :BeijingClothesFactory.javaBeijingClothesFactory.javapublic class BeijingClothesFactory extends ClothesFactorypublic cl

51、ass BeijingClothesFactory extends ClothesFactory public UpperClothes createUpperClothes(int chestSize,int public UpperClothes createUpperClothes(int chestSize,int height) height) return new WesternUpperClothes return new WesternUpperClothes(北京牌西服上衣北京牌西服上衣,chestSize,height,chestSize,height);); public

52、 Trousers createTrousers(int waistSize,int public Trousers createTrousers(int waistSize,int height) height) return new WesternTrousers return new WesternTrousers(北京牌西服褲子北京牌西服褲子,waistSize,height,waistSize,height);); ShanghaiClothesFactory.javaShanghaiClothesFactory.javapublic class ShanghaiClothesFac

53、tory extends ClothesFactorypublic class ShanghaiClothesFactory extends ClothesFactory public UpperClothes createUpperClothes(int chestSize,int public UpperClothes createUpperClothes(int chestSize,int height) height) return new WesternUpperClothes return new WesternUpperClothes(上海牌牛仔上衣上海牌牛仔上衣,chestSi

54、ze,height,chestSize,height);); public Trousers createTrousers(int waistSize,int public Trousers createTrousers(int waistSize,int height) height) return new WesternTrousers return new WesternTrousers(上海牌牛仔褲上海牌牛仔褲,waistSize,height,waistSize,height);); 512022-6-2751模式的結構的描述與使用模式的結構的描述與使用 5 5應用應用_1: _1:

55、 Shop.javaShop.java public class Shoppublic class Shop UpperClothes UpperClothes cloth; cloth; Trousers trouser; Trousers trouser; public void giveSuit(ClothesFactory factory,int chestSize,int waistSize,int public void giveSuit(ClothesFactory factory,int chestSize,int waistSize,int height) height) c

56、loth=factory.createUpperClothes(chestSize,height cloth=factory.createUpperClothes(chestSize,height);); trouser=factory.createTrousers(waistSize,height trouser=factory.createTrousers(waistSize,height);); showMess showMess();(); private void showMess private void showMess()() System.out.println System

57、.out.println();); System.out.println(cloth.getName System.out.println(cloth.getName()+:);()+:); System.out.print( System.out.print(胸圍胸圍:+cloth.getChestSize:+cloth.getChestSize();(); System.out.println System.out.println(身高身高:+cloth.getHeight:+cloth.getHeight();(); System.out.println(trouser.getName

58、System.out.println(trouser.getName()+:);()+:); System.out.print( System.out.print(腰圍腰圍:+trouser.getWaistSize:+trouser.getWaistSize();(); System.out.println System.out.println(身高身高:+trouser.getHeight:+trouser.getHeight();(); 522022-6-2752模式的結構的描述與使用模式的結構的描述與使用 5 5應用應用_2: _2: Application.javaApplicati

59、on.java public class Applicationpublic class Application public static void main(String args public static void main(String args) Shop shop=new Shop(); Shop shop=new Shop(); ClothesFactory factory=new BeijingClothesFactory ClothesFactory factory=new BeijingClothesFactory(); (); shop.giveSuit(factory

60、,110,82,170); shop.giveSuit(factory,110,82,170); factory=new ShanghaiClothesFactory factory=new ShanghaiClothesFactory(); (); shop.giveSuit(factory,120,88,180); shop.giveSuit(factory,120,88,180); 53觀察者模式觀察者模式 2022-6-2753觀察者模式(別名:依賴,發(fā)布觀察者模式(別名:依賴,發(fā)布-訂閱)訂閱) 定義對象間的一種一對多的依賴關系,當一個對象的定義對象間的一種一對多的依賴關系,當一個對

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論