UML實例--HELL_WORLD(四)



This figure makes it clear thatHelloWorld is just a leaf in a larger hierarchy of classes.HelloWorld is a child ofApplet ;Appletis a child ofPanel ;Panelis a child ofContainer; Containeris a child ofComponent ; andComponent is a child ofObject, which is the parent class of every class in Java. This model thus matches the Java library -- each child extends some parent.

圖3-3很清楚的顯示HelloWorld只是一個更大的類層次結構的葉.HelloWorldApplet的子節點;Applet是Panel的子節點;Panel是Container的子節點;Container是Component的子節點;而Component是Object的子節點,Object在Java中是每個類的父節點.這個模型與Java庫一致--每個子節點擴展自多個父節點.

 

The relationship betweenImageObserver andComponent is a bit different, and the class diagram reflects this difference. In the Java library,ImageObserver is an interface, which, among other things, means that it has no implementation and instead requires that other classes implement it. You can show that classComponent implements interfaceImageObserver by the solid line from the rectangle (Component) to a provided interface circle (ImageObserver).

ImageObserverComponent關係有點不同,並且在類圖中已表示出這點不同.在Java庫中,ImageObserver是一個接口,除了別的之外,接口意味着它沒有實現,而是需要其它類實現它.通過從矩形框(Component)連接到表示提供接口的圓的實線顯示Component類實現ImageObserver接口.

 

As these figures show,HelloWorld collaborates directly with only two classes (Applet andGraphics), and these two classes are but a small part of the larger library of predefined Java classes. To manage this large collection, Java organizes its interfaces and classes in a number of different packages. The root package in the Java environment is named, not surprisingly,java. Nested inside this package are several other packages, which contain other packages, interfaces, and classes.Object lives in the packagelang , so its full path name isjava.lang.Object. Similarly,Panel ,Container , andComponent live inawt ; the classApplet lives in the packageapplet . The interfaceImageObserver lives in the packageimage , which in turn lives in the packageawt , so its full path name is the rather lengthy stringjava.awt.image.ImageObserver.

這些圖形表明,與HelloWorld直接交互的只有兩個類(AppletGraphics),且這兩個類是預定義的Java類的大類庫中的一小部分.爲了管理這個大集合,Java將它的接口和類組織在多個不同的包裏.在Java環境的根包命名毫不奇怪的是java. 嵌在這個包裏的是幾個其它的包,這些包包含了其它包,接口和類.Object存在於lang包,所以它的完整路徑爲java.lang.Object.同樣的,Panel ,ContainerComponent存在awt包;類Applet存在applet包;接口ImageObserver存在image包,image又存在於awt包,所以它的完整路徑名是相當長的字符串java.awt.image.ImageObserver.

 

You can visualize this packaging in a class diagram, shown in Figure 3-4. As this figure shows, packages are represented in the UML as a tabbed folders. Packages may be nested, and the dashed directed lines represent dependencies among these packages. For example, HelloWorld depends on the packagejava.applet , andjava.applet depends on the packagejava.awt .

你可以在一個類圖中圖形化這個包,如圖3-4所示.這個圖顯示,包在UML中被帶有標籤的文件夾表示.包可以嵌套,並且包之間的依賴關係由有向虛線表示.例如,HelloWorld依賴java.applet包,java.applet依賴java.awt包.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章