資源描述:
《利用UML類圖設(shè)計(jì)Java應(yīng)用程序詳解.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、利用UML類圖設(shè)計(jì)Java應(yīng)用程序詳解(一)在第一部分中,我們實(shí)現(xiàn)了5個(gè)類。在本部分中,我們接著說明如何利用UML類圖來設(shè)計(jì)余下的各個(gè)類。為減少篇幅,本部分著重講解UML類圖及應(yīng)用,對(duì)Java實(shí)現(xiàn)代碼不再詳細(xì)描述。下載本文全部代碼六、CGPoint類CGPoint類說明了如何利用非抽象類擴(kuò)展抽象類。CGPoint類是CGObject的子類,CGPoint類擴(kuò)展了CGObject類,CGPoint類沒有再它所繼承的變量中增加變量,它所聲明的方法只有構(gòu)造函數(shù)和要求它實(shí)現(xiàn)的抽象方法。其類圖如下:Java實(shí)現(xiàn)代碼為://CGPoi
2、nt.javapublicclassCGPointextendsCGObject{//MethoddeclarationspublicCGPoint(intx,inty,charch){location=newPoint(x,y);drawCharacter=ch;}publicCGPoint(intx,inty){this(x,y,'+');}publicCGPoint(Pointp){this(p.getX(),p.getY(),'+');}publicCGPoint(Pointp,charch){this(p.get
3、X(),p.getY(),ch);}publicvoiddisplay(PrintCGridgrid){grid.setCharAt(drawCharacter,location);}publicvoiddescribe(){System.out.print("CGPoint"+String.valueOf(drawCharacter)+"");System.out.println(location.toString());}}七、CGBox類CGBox類也擴(kuò)展了CGObject類。CGBox類提供了在網(wǎng)格上顯示矩形的附加
4、變量。CGBox類的類圖如下:相應(yīng)的代碼為://CGBox.javapublicclassCGBoxextendsCGObject{//VariabledeclarationsprotectedPointlr;//Lowerrightcornerofabox//MethoddeclarationspublicCGBox(PointulCorner,PointlrCorner,charch){location=ulCorner;lr=lrCorner;drawCharacter=ch;}publicCGBox(Pointul
5、Corner,PointlrCorner){this(ulCorner,lrCorner,'#');}publicvoiddisplay(PrintCGridgrid){intwidth=lr.getX()-location.getX()+1;intheight=lr.getY()-location.getY()+1;PointtopRow=newPoint(location);PointbottomRow=newPoint(location.getX(),lr.getY());for(inti=0;i6、){grid.setCharAt(drawCharacter,topRow);grid.setCharAt(drawCharacter,bottomRow);topRow=topRow.add(1,0);bottomRow=bottomRow.add(1,0);}PointleftCol=newPoint(location);PointrightCol=newPoint(lr.getX(),location.getY());for(inti=0;i>height;++i){grid.setCharAt(drawCharac
7、ter,leftCol);grid.setCharAt(drawCharacter,rightCol);leftCol=leftCol.add(0,1);rightCol=rightCol.add(0,1);}}publicvoiddescribe(){System.out.print("CGBox"+String.valueOf(drawCharacter)+"");System.out.println(location.toString()+""+lr.toString());}}八、CGText類CGText類是CG
8、Object中的第三個(gè)子類。其類圖與代碼分別如下:相應(yīng)的代碼為://CGText.javapublicclassCGTextextendsCGObject{//VariabledeclarationsStringtext;//MethoddeclarationspublicCGText(Pointp,S