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

下載本文檔

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

文檔簡介

第三章 簡單工廠模式5、使用簡單工廠模式設(shè)計一個可以創(chuàng)建不同幾何形狀(Shape),如圓形(Circle)、矩形(Rectangle)和三角形(Triangle)等的繪圖工具類,每個幾何圖形均具有回執(zhí)Draw()和擦除Erase()兩個方案,要求在繪制不支持的幾何圖形時,拋出一個UnsupportedShapeException異常,繪制類圖并使用C#語言編程模擬實現(xiàn)Shape+Draw() : void+Erase() : voidShapeFactory+ShapeProduce(string type) : ShapeCircle+Draw() : void+Erase() : voidTriangle+Draw() : void+Erase() : voidRectangle+Draw() : void+Erase() : voidUnsupportedShapeException+UnsupportedShapeException() 實例類圖:上圖中,Shape接口充當(dāng)抽象產(chǎn)品類,其子類Circle、Triangle、Rectangle和UnsupportedShapeException充當(dāng)具體產(chǎn)品類,ShapeFactory充當(dāng)工廠類。第五章 抽象工廠模式5、一個電器工廠可以生產(chǎn)多種類型的電器,如海爾工廠可以生產(chǎn)海爾電視機、海爾空調(diào)等,TCL工廠可以生產(chǎn)TCL電視機、TCL空調(diào)等,相同品牌的電器構(gòu)成了一個產(chǎn)品族,而相同類型的電器構(gòu)成了一個產(chǎn)品等級結(jié)構(gòu),試使用抽象工廠模式模擬該環(huán)境。實例類圖:ElectricalFactory+CreateTV() : TV+CreateAir_conditioning() : Air_conditioningHaierElectricalFactory+CreateTV() : 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() : voidClient上圖中,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、計算機組裝工廠可以將CPU、內(nèi)存、硬盤、主機、顯示器等硬件設(shè)備組裝在一起構(gòu)成一臺完整的計算機,且構(gòu)成的計算機可以是筆記本,也可以是臺式機,還可以是不提供顯示器的服務(wù)器主機。對于用戶而言,無須關(guān)心計算機的組成設(shè)備和組裝過程,工廠返回給用戶的。是完整的計算機對象,使用建造者模式實現(xiàn)計算機組裝過程,要求繪制類圖并使用C#代碼編程模擬實現(xiàn)。實例類圖:Part- type - cpu - memory - disk - hostComputer - display + Type + CPU + Memory + Disk + HostComputer + Display + set_Type (string value) + get_Type ( ) + set_CPU (string value) + get_CPU ( ) + set_Memory (string value) + get_Memory ( ) + set_Disk (string value) + get_Disk ( ) + set_HosyComputer (string value) + get_HostComputer ( ) + set_Display (string value) + get_Display ( ) : string: string: string: string: string: string: string: string: string: string: string: 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: ComputerComputerAssemble+ Construct(ComputerPartBuilder ab) : ComputerNoteBookBuilder+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): void: void: void: void: void: voidPCBulider+ BuildType()+ BuildCPU()+ BuildMemory()+ BuildDisk()+ BuildHostComputer()+ BuildDisplay(): 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)品。第八章 單例模式6、使用MS Visual Studio設(shè)計一個多文檔窗口(MDI),然后創(chuàng)建一個工具欄(ToolStrip),在工具欄中添加一個按鈕,單擊該按鈕會彈出一個“工具”窗口,使用單例模式進(jìn)行設(shè)計,使得“工具”窗口只能彈出一個,如圖86所示:實例類圖:ToolStrip- Strip : ToolStrip = null- Mini_Tool : ArrayList = null-ToolStrip()+ GetToolStrip() :ToolStrip+ AddTool (string Tool) :void+ RemoveTool (string Tool) :void+ GetTool() :string上圖中,將工具欄ToolStrip設(shè)計為單例角色,其中包含一個工具的集合Mini_Tool,每次在Mini_Tool中隨機選擇一個小工具來相應(yīng)按鈕的請求。第十章 橋接模式5、空客(Airbus)、波音(Boeing)和麥道(McDonnell-Douglas)都是飛機制造商,它們都生產(chǎn)載客飛機(Passenger Plane)和載貨飛機(Cargo Plane)。試設(shè)計一個系統(tǒng),描述這些飛機制造商以及它們所制造的飛機種類。實例類圖:PlaneTypePlane+ DoPlane(PlaneType p): voidPassengerPlane+ DoPlane(PlaneType 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+ PrasePlane(string PlaneName): voidplane上圖中,Manufacturer充當(dāng)抽象類,其子類AirbusManufacturer、BoeingManufacturer和McDonnell_DouglasManufacturer充當(dāng)擴充抽象類;Plane充當(dāng)實現(xiàn)類接口,其子類CargoPlane和PassengerPlane充當(dāng)具體實現(xiàn)類。6、某軟件公司要開發(fā)一個數(shù)據(jù)轉(zhuǎn)換工具,可以將數(shù)據(jù)庫中的數(shù)據(jù)轉(zhuǎn)換成多種文件格式,例如TXT、XML、PDF等格式,同時該工具需要支持多種不同的數(shù)據(jù)庫。試使用橋接模式對其進(jìn)行設(shè)計,并使用C#代碼編程模擬實現(xiàn)。實例類圖:Dataabstract# 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): voidXMLPDFformats+ DoPlane(Content c): void+ PrasePlane(string PlaneName): voidformats上圖中,Data充當(dāng)抽象類,其子類AccessData、和SQLData充當(dāng)擴充抽象類;Dataformats充當(dāng)實現(xiàn)類接口,其子類PDFformats、XMLformats和TXTformats充當(dāng)具體實現(xiàn)類。第十一章 組合模式5、某教育機構(gòu)的組織結(jié)構(gòu)如圖11-8所示:在該教育機構(gòu)OA系統(tǒng)中可以給各級辦公室下發(fā)公文,現(xiàn)采用組合模式設(shè)計該機構(gòu)的組織結(jié)構(gòu),繪制相應(yīng)的類圖并使用C#語言編程模擬實現(xiàn),在客戶端代碼中模擬下發(fā)公文。實例類圖: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 +IssuedDocument() : 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(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 : string + Office (string document) : void +Add( Document file ) : void+Remove(Document file) : void+GetChild(int i) :Abstract +IssuedDocument() : void上圖中,Document充當(dāng)抽象構(gòu)件類,Office充當(dāng)容器構(gòu)件類,Headquarters、Branch、TeachingPoints1和Teaching

溫馨提示

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

評論

0/150

提交評論