軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書(精品)_第1頁
軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書(精品)_第2頁
軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書(精品)_第3頁
軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書(精品)_第4頁
軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書(精品)_第5頁
已閱讀5頁,還剩36頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書 目錄實(shí)驗(yàn)一 經(jīng)典軟件體系結(jié)構(gòu)風(fēng)格(一)1實(shí)驗(yàn)?zāi)康?實(shí)驗(yàn)內(nèi)容11管道-過濾器軟件體系結(jié)構(gòu)12數(shù)據(jù)抽象和面向?qū)ο筌浖w系結(jié)構(gòu)2思考與提高4實(shí)驗(yàn)二 經(jīng)典軟件體系結(jié)構(gòu)風(fēng)格(二)5實(shí)驗(yàn)?zāi)康?實(shí)現(xiàn)內(nèi)容51基于事件的隱式調(diào)用風(fēng)格52層次軟件體系結(jié)構(gòu)6實(shí)驗(yàn)三 分布式軟件體系結(jié)構(gòu)風(fēng)格13實(shí)驗(yàn)?zāi)康?3實(shí)驗(yàn)內(nèi)容13c/s體系結(jié)構(gòu)風(fēng)格13思考與提高14實(shí)驗(yàn)四 mvc風(fēng)格15實(shí)驗(yàn)?zāi)康?5實(shí)驗(yàn)內(nèi)容15mvc的應(yīng)用和編程實(shí)現(xiàn)15實(shí)驗(yàn)五 軟件設(shè)計(jì)的目標(biāo)23實(shí)驗(yàn)?zāi)康?3實(shí)驗(yàn)內(nèi)容231用java語言實(shí)現(xiàn)一個(gè)計(jì)算器程序232健壯性233可維護(hù)性基于面向?qū)ο蠹夹g(shù)的計(jì)算器程序244基于簡單工廠模式的計(jì)算器

2、程序255基于工廠方法模式的計(jì)算器程序27實(shí)驗(yàn)六 軟件設(shè)計(jì)面向?qū)ο蠓椒?9實(shí)驗(yàn)?zāi)康?9實(shí)驗(yàn)內(nèi)容291問題域部分的設(shè)計(jì)對(duì)多重繼承的調(diào)整292數(shù)據(jù)管理部分的設(shè)計(jì)30實(shí)驗(yàn)七 設(shè)計(jì)原則35實(shí)驗(yàn)?zāi)康?5實(shí)驗(yàn)內(nèi)容351里氏代換原則352合成/聚合復(fù)用原則353依賴倒轉(zhuǎn)原則364迪米特法則375接口隔離原則37實(shí)驗(yàn)八 設(shè)計(jì)模式38實(shí)驗(yàn)?zāi)康?8實(shí)驗(yàn)內(nèi)容381單例模式382觀察者模式3839實(shí)驗(yàn)一 經(jīng)典軟件體系結(jié)構(gòu)風(fēng)格(一)實(shí)驗(yàn)?zāi)康模?)理解管道-過濾器軟件體系結(jié)構(gòu)、面向?qū)ο筌浖w系結(jié)構(gòu)的原理(2)掌握管道-過濾器軟件體系結(jié)構(gòu)、面向?qū)ο筌浖w系結(jié)構(gòu)的實(shí)例(3)管道-過濾器軟件體系結(jié)構(gòu)、面向?qū)ο筌浖w系結(jié)構(gòu)的編程

3、實(shí)現(xiàn)實(shí)驗(yàn)內(nèi)容1管道-過濾器軟件體系結(jié)構(gòu)(1)在dos提示符下輸入下面的命令:dir | more使得當(dāng)前目錄列表在屏幕上逐屏顯示。dir的輸出的是整個(gè)目錄列表,它不出現(xiàn)在屏幕上而是由于符號(hào)“|”的規(guī)定,成為下一個(gè)命令more的輸入,more命令則將其輸入一屏一屏地顯示,成為命令行的輸出。(2)java i/o流中的管道流類pipedinputstream和pipedoutputstream可以方便地實(shí)現(xiàn)管道-過濾器體系結(jié)構(gòu),這兩個(gè)類的實(shí)例對(duì)象要通過connect方法連接。下面程序的功能是sender發(fā)送“hello,receiver! im sender”給receiver,然后receive

4、r接受后顯示出來并且在前面加上“the following is from sender”的信息。管道流內(nèi)部在實(shí)現(xiàn)時(shí)還有大量的對(duì)同步數(shù)據(jù)的處理,管道輸出流和管道輸入流執(zhí)行時(shí)不能互相阻塞,以一般要開啟獨(dú)立線程分別執(zhí)行,順便復(fù)習(xí)了多線程操作。import java.io.*;import java.util.*;public class testpipedpublic static void main(string args)sender s = new sender();receiver r = new receiver(); pipedoutputstream out = s.getout()

5、; pipedinputstream in = r.getin(); try in.connect(out); s.start(); r.start(); catch(exception e) e.printstacktrace(); class sender extends thread pipedoutputstream out = new pipedoutputstream(); public pipedoutputstream getout() return out; public void run() string str = hello,receiver ! im sendern;

6、 try out.write(str.getbytes(); out.close(); catch(exception e) e.printstacktrace(); class receiver extends thread pipedinputstream in = new pipedinputstream(); public pipedinputstream getin() return in; public void run() byte buf = new byte1024; try int len = in.read(buf); system.out.println(the fol

7、lowing is from sender:n+new string(buf,0,len); in.close(); catch(exception e) e.printstacktrace(); 程序的執(zhí)行結(jié)果: the following is from sender:hello,receiver ! im sender2數(shù)據(jù)抽象和面向?qū)ο筌浖w系結(jié)構(gòu)有一個(gè)已知的二維坐標(biāo)系,在坐標(biāo)系中定義了若干種規(guī)則的圖形:圓、正方形、矩形和橢圓。使用java語言進(jìn)行面向?qū)ο蟮某绦蛟O(shè)計(jì):(1)首先考慮數(shù)據(jù)封裝性,(2)考慮繼承性,(3)考慮抽象類。abstract class graphprotected

8、 double x,y;/ x,y是規(guī)則圖形的中心點(diǎn)坐標(biāo) public graph(double x,double y)/ 構(gòu)造函數(shù)初始化中心點(diǎn)坐標(biāo) this.x=x; this.y=y; protected void changex(double x)/ 修改橫坐標(biāo) this.x=x; protected void changey(double y)/ 修改縱坐標(biāo) this.y=y; public abstract double area();/ 計(jì)算面積的抽象方法class mysquare extends graph private double length; public mysqu

9、are(double x,double y,double length) super(x,y); this.length=length; protected void changlength(double length) / 修改邊長length this.length=length; public double area() return length*length; class mycircle extends graph private double radius; public mycircle(double x,double y,double radius) super(x,y);

10、this.radius=radius; protected void changradius(double radius) / 修改半徑radius this.radius=radius; public double area() return 3.1416*radius*radius; class myrectangle extends graph private double a,b; public myrectangle(double x,double y,double a,double b) super(x,y); this.a=a; this.b=b; protected void

11、changlength(double length) / 修改長length a=length; protected void changwidth(double width) / 修改寬width b=width; public double area() return a*b; class myellipse extends graph private double a,b; public myellipse (double x,double y,double a,double b) super(x,y); this.a=a; this.b=b; protected void changa

12、(double a) / 修改長軸a this.a=a; protected void changb(double b) / 修改短軸b this.b=b; public double area() return 3.1416*a*b; public class area public static void main (string arg)mycircle c=new mycircle(1,1,3); mysquare s=new mysquare(2,2,4); myrectangle r=new myrectangle(12,9,1,2); myellipse e=new myelli

13、pse(2,-1,3,2); system.out.println(圓c的面積是+c.area(); system.out.println(正方形s的面積是+s.area(); system.out.println(矩形r的面積是+r.area(); system.out.println(橢圓e的面積是+e.area(); 該程序的運(yùn)行結(jié)果為: 圓c的面積是28.2744正方形s的面積是16.0矩形r的面積是2.0橢圓e的面積是18.8496思考與提高1、管道-過濾器軟件體系結(jié)構(gòu)與批處理軟件體系結(jié)構(gòu)的區(qū)別和聯(lián)系是什么?2、面向?qū)ο筌浖w系結(jié)構(gòu)與主程序-子程序軟件體系結(jié)構(gòu)的區(qū)別和聯(lián)系是什么?軟件

14、設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書 實(shí)驗(yàn)二 經(jīng)典體系結(jié)構(gòu)風(fēng)格實(shí)驗(yàn)二 經(jīng)典軟件體系結(jié)構(gòu)風(fēng)格(二)實(shí)驗(yàn)?zāi)康模?)理解基于事件的隱式調(diào)用軟件體系結(jié)構(gòu)、層次軟件體系結(jié)構(gòu)的原理(2)掌握事件的隱式調(diào)用軟件體系結(jié)構(gòu)、層次軟件體系結(jié)構(gòu)的實(shí)例(3)事件的隱式調(diào)用軟件體系結(jié)構(gòu)、層次軟件體系結(jié)構(gòu)的編程實(shí)現(xiàn)實(shí)現(xiàn)內(nèi)容1基于事件的隱式調(diào)用風(fēng)格常用控制組件的事件按鈕與動(dòng)作事件(actionevent),參見下例。按鈕與動(dòng)作事件運(yùn)行結(jié)果import java.awt.*;import java.awt.event.*; /引入java.awt.event包處理事件class btnlabelaction extends frame

15、implements actionlistener/聲明窗口類(btnlabelaction)并實(shí)現(xiàn)動(dòng)作事件接口(actionlistener)label prompt;button btn;void createwindow() /自定義方法settitle(mybutton);prompt = new label(你好);/創(chuàng)建標(biāo)簽對(duì)象btn = new button(操作);/創(chuàng)建按鈕對(duì)象setlayout(new flowlayout();/布局設(shè)計(jì),用于安排按鈕、標(biāo)簽的位置add(prompt);/將標(biāo)簽放入容器add(btn);/將按鈕放入容器btn.addactionlisten

16、er(this);/將監(jiān)聽器(窗體對(duì)象本身)注冊(cè)給按鈕對(duì)象setsize(300,100);setvisible(true);public void actionperformed(actionevent e)/接口actionlistener的事件處理方法if(e.getsource()=btn) /判斷動(dòng)作事件是否是由按鈕btn引發(fā)的if(prompt.gettext()=你好)prompt.settext(再見);elseprompt.settext(你好); public class btntestpublic static void main (string args)btnlabe

17、laction bla=new btnlabelaction();bla.createwindow(); 2層次軟件體系結(jié)構(gòu)基于層次軟件體系結(jié)構(gòu)的軟件測試系統(tǒng)。第一層為用戶圖形界面層import java.awt.*;import java.util.*;import javax.swing.*;import java.awt.event.*;import com.sun.java.swing.plaf.windows.*;public class testinggui extends jpanel private jtextarea txttestinfo, txttestcase; pri

18、vate jlabel lbltestcases; private jpanel buttonpanel; private jcombobox cmbtestcases; private static final string case_bubble= tc1-test bubble sort; private static final string case_heap= tc2-test heap sort; private static final string case_insertion= tc3-test insertion sort; private static final st

19、ring execute = execute; private static final string exit = exit; public testinggui() txttestinfo=new jtextarea(test output from source shown heren, 6, 20); txttestinfo.setlinewrap(true); txttestcase = new jtextarea(testcase info and test validation shown heren, 4, 15); txttestcase.setlinewrap(true);

20、 buildupscrollgui(); private void buildupscrollgui() setupbuttonpanel(); jscrollpane btnpane = new jscrollpane(buttonpanel); jscrollpane textpane = new jscrollpane(txttestcase); textpane.setminimumsize(new dimension(250, 150); jscrollpane testdatapane = new jscrollpane(txttestinfo); jsplitpane upspl

21、itpane = new jsplitpane(jsplitpane.horizontal_split); upsplitpane.setleftcomponent(btnpane); upsplitpane.setrightcomponent(testdatapane); jscrollpane downpane = new jscrollpane(textpane); dimension minimumsize = new dimension(130, 100); btnpane.setminimumsize(minimumsize); textpane.setminimumsize(ne

22、w dimension(100, 100); upsplitpane.setdividerlocation(270); upsplitpane.setpreferredsize(new dimension(500, 300); jsplitpane bigsplitpane = new jsplitpane(jsplitpane.vertical_split, upsplitpane, downpane); bigsplitpane.setdividerlocation(190); add(bigsplitpane); setsize(new dimension(500, 400); setv

23、isible(true); private void setupbuttonpanel() lbltestcases = new jlabel(test cases:); cmbtestcases = new jcombobox(); cmbtestcases.additem(case_bubble); cmbtestcases.additem(case_heap); cmbtestcases.additem(case_insertion); /create the open button jbutton executebtn = new jbutton(execute); executebt

24、n.setmnemonic(keyevent.vk_s); jbutton exitbutton = new jbutton(exit); exitbutton.setmnemonic(keyevent.vk_x); btnlistener objbuttonhandler = new btnlistener(); / add action listener executebtn.addactionlistener(objbuttonhandler); exitbutton.addactionlistener(objbuttonhandler); buttonpanel = new jpane

25、l(); gridbaglayout gridbag = new gridbaglayout(); buttonpanel.setlayout(gridbag); gridbagconstraints gbc = new gridbagconstraints(); buttonpanel.add(lbltestcases); buttonpanel.add(cmbtestcases); buttonpanel.add(executebtn); buttonpanel.add(exitbutton); gbc.insets.top = 5; gbc.insets.bottom = 5; gbc.

26、insets.left = 5; gbc.insets.right = 5; gbc.anchor = gridbagconstraints.east; gbc.gridx = 0; gbc.gridy = 0; gridbag.setconstraints(lbltestcases, gbc); gbc.anchor = gridbagconstraints.west; gbc.gridx = 1; gbc.gridy = 0; gridbag.setconstraints(cmbtestcases, gbc); gbc.anchor = gridbagconstraints.east; g

27、bc.insets.left = 2; gbc.insets.right = 2; gbc.insets.top = 25; gbc.anchor = gridbagconstraints.east; gbc.gridx = 0; gbc.gridy = 7; gridbag.setconstraints(executebtn, gbc); gbc.anchor = gridbagconstraints.west; gbc.gridx = 1; gbc.gridy = 7; gridbag.setconstraints(exitbutton, gbc); public void showtes

28、tinfo(int str ) txttestinfo.settext(); for(int n=0; n str.length; n+) txttestinfo.append(+strn+ ); public void showerrors(string err) txttestcase.append(err+n); public string getselectedtestcase() return (string) cmbtestcases.getselecteditem(); class btnlistener implements actionlistener private tes

29、tcase test; private string selectedtestcase; public void actionperformed(actionevent e) string searchresult = null; int output=null; if (e.getactioncommand().equals(exit) system.exit(1); if (e.getactioncommand().equals(execute) selectedtestcase = getselectedtestcase(); if(selectedtestcase.equals(cas

30、e_bubble) test = new testcasebubble(); else if(selectedtestcase.equals(case_heap) test = new testcaseheap(); else if(selectedtestcase.equals(case_insertion) test = new testcaseinsertion(); output = test.execute(3000); showtestinfo(output); showerrors(selectedtestcase); boolean result = resultverific

31、ation.isresultcorrect(output ); showerrors(no error found = +result); long timetaken = test.gettimetaken(); showerrors(testing time takes = + timetaken+n); / end of class btnlistener private static void createandshowgui() jframe.setdefaultlookandfeeldecorated(true); jframe frame = new jframe(layered

32、 architecture- software testing); frame.setdefaultcloseoperation(jframe.exit_on_close); testinggui newcontentpane = new testinggui(); newcontentpane.setopaque(true); frame.setcontentpane(newcontentpane); frame.pack(); frame.setvisible(true); static public void main(string argv) javax.swing.swingutil

33、ities.invokelater(new runnable() public void run() createandshowgui(); ); public class resultverification static boolean flag = true; public static boolean isresultcorrect(int arr) for(int k=0; k arrk+1) flag=false; system.out.println(error + k); /break; return flag; 第二層為測試案例層,包括軟件測試工程師所編寫的測試案例publi

34、c interface testcase public abstract int execute(int len); public abstract long gettimetaken();class context sortalgorithm alg; / constructor public context(sortalgorithm alg) this.alg = alg; public int sortintarray(int a) return this.alg.sort(a); import java.util.random;public class integerarrgener

35、ator public static int generateinput(int len) int input= new intlen; random r = new random(); for(int m=0; m= 0;) for(int j = 0; j numsj + 1) /exchange numsj+1 with numsj int t = numsj; numsj = numsj + 1; numsj + 1 = t; return nums; public class heapsort implements sortalgorithm public int sort(int

36、nums ) for(int i=nums.length; i1; i-) buildbinaryheaptree(nums, i - 1); swapleadingnodewithlastnode(nums, i - 1); return nums; public void buildbinaryheaptree(int array, int arraybound) int leftchild, rightchild, biggerchild, temp; int root = (arraybound-1)/2; / find the bigger child index for(int i

37、=root; i=0; i-) leftchild = (2*i)+1; rightchild = (2*i)+2; if(leftchild = arraybound) & (rightchild = arrayleftchild) biggerchild = rightchild; else biggerchild = leftchild; else if(rightchild arraybound) biggerchild = leftchild; else biggerchild = rightchild; /swap the integer contained in the bigg

38、er child index /with that in the current parent node if(arrayi arraybiggerchild) temp = arrayi; arrayi = arraybiggerchild; arraybiggerchild = temp; return;public static void swapleadingnodewithlastnode(int array, int arraybound) int temp; temp = array0; array0 = arrayarraybound; arrayarraybound = te

39、mp; return;public class insertsort implements sortalgorithm public int sort(int nums) for (int i = 1; i 0) & (numsj-1 numtobeinserted) ) numsj = numsj-1; j-; numsj = numtobeinserted; return nums; 軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)指導(dǎo)書 實(shí)驗(yàn)三 分布式軟件體系結(jié)構(gòu)風(fēng)格實(shí)驗(yàn)三 分布式軟件體系結(jié)構(gòu)風(fēng)格實(shí)驗(yàn)?zāi)康模?)理解分布式軟件體系結(jié)構(gòu)風(fēng)格的原理(2)掌握分布式軟件體系結(jié)構(gòu)風(fēng)格的實(shí)例(3)常見分布式軟件體系結(jié)構(gòu)風(fēng)格的

40、編程實(shí)現(xiàn)實(shí)驗(yàn)內(nèi)容c/s體系結(jié)構(gòu)風(fēng)格客戶機(jī)發(fā)送數(shù)據(jù)到服務(wù)器,服務(wù)器將收到的數(shù)據(jù)返回給客戶機(jī),直到接收到字符串“end”為止,最后關(guān)閉連接。(1)服務(wù)器端程序tcpserver.javaimport java.io.*;import .*;public class tcpserver public static final int port=8888; public static void main(string args) throws ioexception /建立serversocket serversocket s=new serversocket(port); system.out.println(serversocket:+s); try /*程序阻塞,等待連接。即直到有一個(gè)客戶請(qǐng)求到達(dá),程序方能繼續(xù)執(zhí)行*/ socket ss=s.accept(); system.out.println(socket accept:+ss); try /連接成功,建立相應(yīng)的i/o數(shù)據(jù)流 datainputstream dis=new datainputst

溫馨提示

  • 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)論