軟件需求分析與設(shè)計(jì)-簡(jiǎn)單實(shí)現(xiàn)_第1頁(yè)
軟件需求分析與設(shè)計(jì)-簡(jiǎn)單實(shí)現(xiàn)_第2頁(yè)
軟件需求分析與設(shè)計(jì)-簡(jiǎn)單實(shí)現(xiàn)_第3頁(yè)
軟件需求分析與設(shè)計(jì)-簡(jiǎn)單實(shí)現(xiàn)_第4頁(yè)
軟件需求分析與設(shè)計(jì)-簡(jiǎn)單實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩19頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、軟件需求分析與設(shè)計(jì)簡(jiǎn)單實(shí)現(xiàn)2022-7-22簡(jiǎn)單實(shí)現(xiàn) 主要內(nèi)容 對(duì)可見(jiàn)性進(jìn)行設(shè)計(jì) 將設(shè)計(jì)映射為代碼 測(cè)試驅(qū)動(dòng)開(kāi)發(fā)和重構(gòu)2022-7-23可見(jiàn)性設(shè)計(jì) 對(duì)象之間的可見(jiàn)性 為了使發(fā)送者對(duì)象能夠向接收者對(duì)象發(fā)送消息,發(fā)送者必須具有接受者的可見(jiàn)性 可見(jiàn)性 是對(duì)象看到或者引用其他對(duì)象的能力 與范圍有關(guān) 四種類型 屬性可見(jiàn)性B是A的屬性 參數(shù)可見(jiàn)性B是A中方法的參數(shù) 局部可見(jiàn)性B是A中方法的局部對(duì)象不是參數(shù) 全局可見(jiàn)性B具有某種方法的全局可見(jiàn)性2022-7-24從Register到ProductCatalog的可見(jiàn)性是必須的: RegisterenterItem(itemID, quantity): Pro

2、ductCatalogdesc = getProductDesc( itemID )public void enterItem( itemID, qty ) . desc = catalog.getProductDesc(itemID) .class Register . private ProductCatalog catalog; .2022-7-25屬性可見(jiàn)性: RegisterenterItem(itemID, quantity): ProductCatalogdesc = getProductDesc ( itemID )public void enterItem (itemID,

3、qty) . desc = catalog.getProductDesc(itemID) .class Register . private ProductCatalog catalog ; .2022-7-26參數(shù)可見(jiàn)性2: makeLineItem(desc, qty)enterItem(id, qty)1: desc = getProductDesc(id)2.1: create(desc, qty):Register:Sale:ProductCatalogsl : SalesLineItemmakeLineItem(ProductDescription desc , int qty)

4、. sl = new SalesLineItem (desc, qty); .2022-7-27屬性可見(jiàn)性的參數(shù)2: makeLineItem(desc, qty)enterItem(id, qty)2: desc = getProductDesc(id)2.1: create(desc, qty):Register:Sale:ProductCatalogsl : SalesLineItem/ initializing method (e.g., a Java constructor)SalesLineItem(ProductDescription desc, int qty) .descri

5、ption = desc; / parameter to attribute visibility.2022-7-28局部可見(jiàn)性: RegisterenterItem(itemID, quantity): ProductCatalogdesc = getProductDesc( itemID )enterItem(id, qty) ./ local visibility via assignment of returning objectProductDescription desc = catalog.getProductDes(id);.實(shí)現(xiàn)局部可見(jiàn)性的兩種方式:創(chuàng)立新的局部實(shí)例并將其分配

6、給局部變量將方法調(diào)用返回的對(duì)象分配給局部變量2022-7-29將設(shè)計(jì)映射為代碼 將設(shè)計(jì)映射為代碼 類和接口的定義 方法的定義 由 DCD創(chuàng)立類的定義 DCD描述了類或接口的名稱、超類、操作的特征標(biāo)記以及類的屬性,可以從類圖直接生成類的定義 從交互圖創(chuàng)立方法 交互圖中的一系列消息可以轉(zhuǎn)化為方法定義中的一系列語(yǔ)句2022-7-210Java中的SaleLineItempublic class SalesLineItemprivate int quantity;private ProductDescription description;public SalesLineItem(ProductDes

7、cription desc, int qty) . public Money getSubtotal() . SalesLineItemquantity : IntegergetSubtotal() : MoneyProductDescription description : Textprice : MoneyitemID : ItemID.1description2022-7-211enterItem交互圖2: makeLineItem(desc, qty)enterItem(id, qty)1: desc = getProductDesc(id)2.1: create(desc, qty

8、)1.1: desc = get(id):Register:Sale:ProductCatalogsl: SalesLineItemlineItems : List: Map2.2: add(sl)2022-7-212Register類ProductCatalog.getProductDesc(.)SaleisComplete : Booleantime : DateTimebecomeComplete()makeLineItem(.)makePayment(.)getTotal()Register.endSale()enterItem(id: ItemID, qty : Integer)ma

9、keNewSale()makePayment(cashTendered : Money)public class Registerprivate ProductCatalog catalog;private Sale currentSale;public Register(ProductCatalog pc) .public void endSale() .public void enterItem(ItemID id, int qty) .public void makeNewSale() .public void makePayment(Money cashTendered) .11cat

10、alogcurrentSale2022-7-213enterItem方法2: makeLineItem (desc, qty)enterItem(id, qty)1: desc := getProductDescription (id):Register:Sale:ProductCatalog ProductDescription desc = catalog.ProductDescription (id); currentSale .makeLineItem (desc, qty);2022-7-214代碼中的集合類SalesLineItemquantity : IntegergetSubt

11、otal()1.*SaleisComplete : Booleantime : DateTimebecomeComplete()makeLineItem()makePayment()getTtotal()public class Sale.private List lineItems = new ArrayList();A collection class is necessary to maintain attribute visibility to all the SalesLineItems.lineItems2022-7-215定義Sale.makeLineItem方法 lineIte

12、ms.add( new SalesLineItem (desc, qty) );2: makeLineItem(desc, qty)enterItem(id, qty)2.1: create(desc, qty):Register:Salesl: SalesLineItemlineItems :List2.2: add(sl)2022-7-216實(shí)現(xiàn)和測(cè)試類的可能順序SalesLineItemquantity : IntegergetSubtotal()ProductCatalog.getProductDesc (.)ProductDescriptiondescription : Textpr

13、ice : MoneyitemID : ItemID.Storeaddress : Addressname : TextaddSale(.)Paymentamount : Money.1.*1.*Register.endSale()enterItem(.)makeNewSale ()makePayment (.)SaleisComplete : Booleantime : DateTimebecomeComplete ()makeLineItem (.)makePayment (.)getTotal().111111*1234567轉(zhuǎn)換后代碼2022-7-217測(cè)試驅(qū)動(dòng)開(kāi)發(fā)和重構(gòu) 測(cè)試驅(qū)動(dòng)開(kāi)發(fā)

14、TDD) 是迭代和敏捷XP方法提倡的優(yōu)秀實(shí)踐 首先編寫測(cè)試,然后編寫預(yù)計(jì)要測(cè)試的代碼 優(yōu)點(diǎn) 能夠保證編寫單元測(cè)試 使程序員獲得滿足感從而更始終如一地堅(jiān)持編寫測(cè)試 有助于澄清接口和行為的細(xì)節(jié) 可證明、可再現(xiàn)、自動(dòng)的驗(yàn)證 改變事物的信息2022-7-218測(cè)試驅(qū)動(dòng)開(kāi)發(fā)和重構(gòu) 重構(gòu) 是重寫和重新構(gòu)建已有代碼的結(jié)構(gòu)化和規(guī)律性方法,但不會(huì)改變已有代碼的外在行為,而是采用一系列少量轉(zhuǎn)換的步驟,并且每一步都結(jié)合了重新執(zhí)行的測(cè)試 重構(gòu)的本質(zhì)是一次實(shí)行一小步保存行為的轉(zhuǎn)換 每次重構(gòu)都是小量的 目標(biāo) 去除冗余代碼 改變清晰度 使過(guò)長(zhǎng)的方法變的較短 去除硬編碼字面常量2022-7-219測(cè)試驅(qū)動(dòng)開(kāi)發(fā)和重構(gòu) 重構(gòu) 壞

15、味代碼 冗余的代碼 大型方法 具有大量代碼的類 明顯相似的子類 在設(shè)計(jì)中很少使用或沒(méi)有使用接口 許多對(duì)象之間有很多的耦合度 包含大量其他的垃圾代碼2022-7-220重構(gòu)樣例重構(gòu)描述提煉方法(Extract Method)將較長(zhǎng)的方法轉(zhuǎn)換為較短的方法,其中將原有方法中的部分內(nèi)容分解外私有的幫助者方法(helper method)提煉常量( Extract Constant )使用常量變量(constant variable)替換字面常量引入解釋變量(提煉局部變量的特化)將表達(dá)式的部分或完整結(jié)果置入臨時(shí)變量,該變量的名字應(yīng)該能購(gòu)說(shuō)明其目的使用工廠方法代替構(gòu)造器調(diào)用例如在Java中調(diào)用創(chuàng)建對(duì)象的幫

16、助者方法(helper method)來(lái)代替對(duì)新操作和構(gòu)造器的調(diào)用(隱藏細(xì)節(jié))2022-7-221重構(gòu)之前的takeTurn方法public class Playerprivate Piece piece;private Board board;private Die dice;/ public void takeTurn()/ roll diceint rollTotal = 0;for (int i = 0; i dice.length; i+)dicei.roll();rollTotal += dicei.getFaceValue();Square newLoc = board.getS

17、quare(piece.getLocation(), rollTotal);piece.setLocation(newLoc); / end of class2022-7-222提煉方法重構(gòu)之后的代碼public class Playerprivate Piece piece;private Board board;private Die dice;/ public void takeTurn()/ the refactored helper methodint rollTotal = rollDice();Square newLoc = board.getSquare(piece.getLo

18、cation(), rollTotal);piece.setLocation(newLoc);private int rollDice()int rollTotal = 0;for (int i = 0; i dice.length; i+)dicei.roll();rollTotal += dicei.getFaceValue();return rollTotal; / end of class2022-7-223引入解釋變量之前/ good method name, but the logic of the body is not clearboolean isLeapYear( int year )return( ( ( year % 400 ) = 0 ) | ( ( ( year % 4 ) = 0 ) & ( ( y

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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)論