C#模式設(shè)計(jì)習(xí)題分析_第1頁
C#模式設(shè)計(jì)習(xí)題分析_第2頁
C#模式設(shè)計(jì)習(xí)題分析_第3頁
C#模式設(shè)計(jì)習(xí)題分析_第4頁
C#模式設(shè)計(jì)習(xí)題分析_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、第三章 簡單工廠模式5、使用簡單工廠模式設(shè)計(jì)一個(gè)可以創(chuàng)建不同幾何形狀(Shape),如圓形(Circle)、矩形(Rectangle)和三角形(Triangle)等的繪圖工具類,每個(gè)幾何圖形均具有回執(zhí)Draw()和擦除Erase()兩個(gè)方案,要求在繪制不支持的幾何圖形時(shí),拋出一個(gè)UnsupportedShapeException異常,繪制類圖并使用C#語言編程模擬實(shí)現(xiàn)<<create>><<create>><<create>>Shape+Draw() : void+Erase() : voidShapeFactory+Sh

2、apeProduce(string type) : ShapeCircle+Draw() : void+Erase() : voidTriangle+Draw() : void+Erase() : voidRectangle+Draw() : void+Erase() : voidUnsupportedShapeException+UnsupportedShapeException() 實(shí)例類圖:上圖中,Shape接口充當(dāng)抽象產(chǎn)品類,其子類Circle、Triangle、Rectangle和UnsupportedShapeException充當(dāng)具體產(chǎn)品類,ShapeFactory充當(dāng)工廠類。第

3、五章 抽象工廠模式5、一個(gè)電器工廠可以生產(chǎn)多種類型的電器,如海爾工廠可以生產(chǎn)海爾電視機(jī)、海爾空調(diào)等,TCL工廠可以生產(chǎn)TCL電視機(jī)、TCL空調(diào)等,相同品牌的電器構(gòu)成了一個(gè)產(chǎn)品族,而相同類型的電器構(gòu)成了一個(gè)產(chǎn)品等級(jí)結(jié)構(gòu),試使用抽象工廠模式模擬該環(huán)境。實(shí)例類圖:<<create>><<create>><<create>>ElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningHaierElectricalFactory+Creat

4、eTV() : TV+CreateAir_conditioning() : Air_conditioningTCLElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningHaierAir_conditioning+Display() : voidTCLAir_conditioning+Display() : voidHaierTV+Display() : voidTCLTV+Display() : voidAir_conditioning+Display() : voidTV+Display()

5、: voidClient<<create>>上圖中,ElectricalFactory接口充當(dāng)抽象工廠,其子類HaierElectricalFactory和TCLElectricalFactory充當(dāng)具體工廠,接口Air_conditioning和TV充當(dāng)抽象產(chǎn)品,其子類HaierAir_conditionin、TCLAir_conditioning、HaierTV和TCLTV充當(dāng)具體產(chǎn)品。第六章 建造者模式4、計(jì)算機(jī)組裝工廠可以將CPU、內(nèi)存、硬盤、主機(jī)、顯示器等硬件設(shè)備組裝在一起構(gòu)成一臺(tái)完整的計(jì)算機(jī),且構(gòu)成的計(jì)算機(jī)可以是筆記本,也可以是臺(tái)式機(jī),還可以是不提供顯示器的

6、服務(wù)器主機(jī)。對(duì)于用戶而言,無須關(guān)心計(jì)算機(jī)的組成設(shè)備和組裝過程,工廠返回給用戶的。是完整的計(jì)算機(jī)對(duì)象,使用建造者模式實(shí)現(xiàn)計(jì)算機(jī)組裝過程,要求繪制類圖并使用C#代碼編程模擬實(shí)現(xiàn)。實(shí)例類圖:Part-<<PropertyImplementation>> type -<<PropertyImplementation>> cpu -<<PropertyImplementation>> memory -<<PropertyImplementation>> disk -<<PropertyImplem

7、entation>> hostComputer -<<PropertyImplementation>> display +<<Property>> Type +<<Property>> CPU +<<Property>> Memory +<<Property>> Disk +<<Property>> HostComputer +<<Property>> Display +<<Setter>>

8、set_Type (string value) +<<Getter>> get_Type ( ) +<<Setter>> set_CPU (string value) +<<Getter>> get_CPU ( ) +<<Setter>> set_Memory (string value) +<<Getter>> get_Memory ( ) +<<Setter>> set_Disk (string value) +<<Getter>

9、> get_Disk ( ) +<<Setter>> set_HosyComputer (string value) +<<Getter>> get_HostComputer ( ) +<<Setter>> set_Display (string value) +<<Getter>> get_Display ( ) : string: string: string: string: string: string: string: string: string: string: string:

10、string: void: string: void: string: void: string: void: string: void: string: void: stringComputerPartBuilder abstract # computer Computer = new Computer()+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay()+ CreateComputer(): void: void: void: void: void: void:

11、 ComputerComputerAssemble+ Construct(ComputerPartBuilder ab) : ComputerNoteBookBuilder+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void: void: void: void: voidPCBulider+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ Bui

12、ldDisplay(): void: void: void: void: void: voidServerBulider+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void: void: void: void: void上圖中,ComputerAssemble 充當(dāng)指揮者,ComputerPartBuilder 充當(dāng)抽象建造者,NoteBookBuilder、PCBulider和ServerBulider充當(dāng)具體建造者,Part充當(dāng)復(fù)雜產(chǎn)品。第

13、八章 單例模式6、使用MS Visual Studio設(shè)計(jì)一個(gè)多文檔窗口(MDI),然后創(chuàng)建一個(gè)工具欄(ToolStrip),在工具欄中添加一個(gè)按鈕,單擊該按鈕會(huì)彈出一個(gè)“工具”窗口,使用單例模式進(jìn)行設(shè)計(jì),使得“工具”窗口只能彈出一個(gè),如圖86所示:實(shí)例類圖:ToolStrip- Strip : ToolStrip = null- Mini_Tool : ArrayList = null-ToolStrip()+ GetToolStrip() :ToolStrip+ AddTool (string Tool) :void+ RemoveTool (string Tool) :void+ Get

14、Tool() :string上圖中,將工具欄ToolStrip設(shè)計(jì)為單例角色,其中包含一個(gè)工具的集合Mini_Tool,每次在Mini_Tool中隨機(jī)選擇一個(gè)小工具來相應(yīng)按鈕的請(qǐng)求。第十章 橋接模式5、空客(Airbus)、波音(Boeing)和麥道(McDonnell-Douglas)都是飛機(jī)制造商,它們都生產(chǎn)載客飛機(jī)(Passenger Plane)和載貨飛機(jī)(Cargo Plane)。試設(shè)計(jì)一個(gè)系統(tǒng),描述這些飛機(jī)制造商以及它們所制造的飛機(jī)種類。實(shí)例類圖:PlaneTypePlane+ DoPlane(PlaneType p): voidPassengerPlane+ DoPlane(Pl

15、aneType p): voidCargoPlane+ DoPlane(PlaneType p): voidManufacturerabstract# plane: Plane+ SetPlane(Plane plane): void+ PrasePlane(string PlaneName): voidAirbusManufacturer+ PrasePlane(string PlaneName): voidBoeingManufacturer+ PrasePlane(string PlaneName): voidMcDonnell_DouglasManufacturer+ PrasePla

16、ne(string PlaneName): voidplane上圖中,Manufacturer充當(dāng)抽象類,其子類AirbusManufacturer、BoeingManufacturer和McDonnell_DouglasManufacturer充當(dāng)擴(kuò)充抽象類;Plane充當(dāng)實(shí)現(xiàn)類接口,其子類CargoPlane和PassengerPlane充當(dāng)具體實(shí)現(xiàn)類。6、某軟件公司要開發(fā)一個(gè)數(shù)據(jù)轉(zhuǎn)換工具,可以將數(shù)據(jù)庫中的數(shù)據(jù)轉(zhuǎn)換成多種文件格式,例如TXT、XML、PDF等格式,同時(shí)該工具需要支持多種不同的數(shù)據(jù)庫。試使用橋接模式對(duì)其進(jìn)行設(shè)計(jì),并使用C#代碼編程模擬實(shí)現(xiàn)。實(shí)例類圖:Dataabstract#

17、 formats:Dataformats+ SetDataformats(Dataformats formats): void+ ParseFile(string fileName): voidAccessData+ ParseFile(string fileName): voidSQLData+ ParseFile(string fileName): voidContentDataformats+ DoContent(Content c): void:: voidTXTformats+ DoPlane(Content c): voidPDFformats+ DoPlane(Content c

18、): voidXMLPDFformats+ DoPlane(Content c): void+ PrasePlane(string PlaneName): voidformats上圖中,Data充當(dāng)抽象類,其子類AccessData、和SQLData充當(dāng)擴(kuò)充抽象類;Dataformats充當(dāng)實(shí)現(xiàn)類接口,其子類PDFformats、XMLformats和TXTformats充當(dāng)具體實(shí)現(xiàn)類。第十一章 組合模式5、某教育機(jī)構(gòu)的組織結(jié)構(gòu)如圖11-8所示:在該教育機(jī)構(gòu)OA系統(tǒng)中可以給各級(jí)辦公室下發(fā)公文,現(xiàn)采用組合模式設(shè)計(jì)該機(jī)構(gòu)的組織結(jié)構(gòu),繪制相應(yīng)的類圖并使用C#語言編程模擬實(shí)現(xiàn),在客戶端代碼中模擬下發(fā)公

19、文。實(shí)例類圖:officeListDocument abstract +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidHeadquarters-document : string +Headquarters(string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +I

20、ssuedDocument() : voidBranch-document : string + Branch (string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) :Abstract +IssuedDocument() : voidTeachingPoints1-document : string + TeachingPoints1(string document) : void +Add( Document file ) : void+Remove

21、(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidTeachingPoints2-document : string + TeachingPoints2(string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) : Abstract +IssuedDocument() : voidOffice-officeList : List<Document>-document : string + Office (string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) :Abstract +IssuedDocument() : v

溫馨提示

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

評(píng)論

0/150

提交評(píng)論