6. theFlooring發送一個消息getWidth ()給theSurface
7. theSurface發送一個回應給theFlooring
8. theFlooring發送一個回應給FlooringClient
二、getTotalPrice()方法
在FlooringClient程序中,我們有如下語句:
double price=theFlooring.getTotalPrice(theSurface);
getTotalPrice()方法為:
public double getTotalPrice(Surface aSurface) {
return getNoOfMeters(aSurface) * price;
}
該過程用UML序列圖描述如下圖:

三、同一個類的兩個對象之間的交互
一個對象可以與同一個類的另一個對象交互從而完成程序所規定的任務。如果我們在Surface類中增加一個比較面積的方法。程序代碼為:
public int compareAreas(Surface theOtherSurface){
final double precision=0.00001;
double area1=getArea();
double area2=theOtherSurface.getArea();
文章來源于領測軟件測試網 http://www.kjueaiud.com/