UML基本架構建模--獲取關聯



If you are building a house, things like walls, doors, windows, cabinets, and lights will form part of your vocabulary. None of these things stands alone, however. Walls connect to other walls. Doors and windows are placed in walls to form openings for people and for light. Cabinets and lights are physically attached to walls and ceiling. You group walls, doors, windows, cabinets, and lights together to form higher-level things, such as rooms.

如果你正在建房子,象牆,門,窗,櫃和燈這類事物將形成你詞彙表中的一部分.然而這類事物都不能獨立存在.牆需要與其它牆相連.門和窗被固定在牆上,對人和光線形成開口.櫃和燈完全地嵌在牆和天花板裏.你將牆,門,窗,櫃和燈組合在一起形成更高層的事物,比如房間.

 

Not only will you find structural relationships among these things, you’ll find other kinds of relationships as well. For example, your house certainly has windows, but there are probably many kinds of windows. You might have large bay windows that don’t open, as well as small kitchen windows that do. Some of your windows might open up and down; others, like patio windows, will slide left and right. Some windows have a single pane of glass; others have double. No matter their differences, there is some essential window-ness about each of them: Each is an opening in a wall, and each is designed to let in light, air, and sometimes, people.

你不僅會在這些事物之間找到結構關係,還能找到其它類別的關係.舉個例子,你的房子肯定有窗戶,但可能有很多不同的窗戶,可能有不需要打開的大吊窗,也會有小廚房那樣的窗戶;窗戶中有些是上下打開,其它如庭院的窗戶,則是左右開窗;窗戶中有些是單層玻璃,另一些是雙層玻璃.無論它們之間有什麼差異,它們中的每個都有基本的窗口屬性:都是嵌在牆裏的,都被設計爲讓光,空氣,有時是人進入.

 

In the UML, the ways that things can connect to one another, either logically or physically, are modeled as relationships. In object-oriented modeling, there are three kinds of relationships that are most important: dependencies, generalizations, and associations.

在UML中,事物被連接到另一個事物的方法,不管是邏輯上還是物理上,都被作爲關聯建模.在面向對象建模中,有三種最重要的關聯:依賴,泛化和聯合.

 

1.Dependencies are using relationships. For example, pipes depend on the water heater to heat the water they carry.

依賴是使用的關聯.舉個例子,管道依靠熱水器把它們裝運的水加熱.

 

2.Associations are structural relationships among instances. For example, rooms consist of walls and other things; walls themselves may have embedded doors and windows; pipes may pass through walls.

聯合是實例之間的結構關聯.比如,房間由牆和其它事物組成;牆本身可能有嵌入的門和窗;管道可能穿牆而過.

 

3.Generalizations connect generalized classes to more-specialized ones in what is known as subclass/superclass or child/parent relationships. For example, a picture window is a kind of window with very large, fixed panes; a patio window is a kind of window with panes that open side to side.

泛化建立廣義類和更專業類之間的聯繫,被稱爲子類/超類或是子/父的關聯.比如,以繪畫裝飾的窗戶很大且玻璃窗固定;庭院的窗戶的玻璃是能從一邊向另一邊打開的.

 

These three kinds of relationships cover most of the important ways in which things collaborate with one another. Not surprisingly, they also map well to the ways that are provided by most object-oriented programming languages to connect objects.

這三類關係涵蓋了事物互相協作的大部分的重要的方面.毫不奇怪的是,它們也能很好的映射到大多數面向對象程序語言提供的連接對象的方法.

 

The UML provides a graphical representation for each of these kinds of relationships, as Figure 5-1 shows. This notation permits you to visualize relationships apart from any specific programming language, and in a way that lets you emphasize the most important parts of a relationship: its name, the things it connects, and its properties.

UML爲這些關聯的每一個提供了一個圖形化的表達方式,如圖5-1所示,這個標識允許你脫離任何特定的編程語言將關聯可視化,用這種方式能讓你理解關聯的最重要部分:它的名字,它連接的事物和它的屬性.

圖片

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