UML精粹--标准对象建模语言简明教程
今天借了一本《UML精粹--標準對象建模語言簡明教程》(Uml Distilled: A Brief Guide to the Standard Object Modeling Language)。徐家福先生譯過來的。總體上感覺:把一本好書糟蹋了。之乎者也的序自不待言。諸如“如果萬一有人不小心面陷入我的陷阱,控制器對象終止,于是我就需要把兔子關(guān)入籠內(nèi),擦擦地板,重新啟動系統(tǒng)?!敝惖姆g(我查了下原著,if someone should be so careless as to fall for my trap,the controller object terminates,so I would need to put the rabbit in its cage,mop the floor,and reboot the system.),讓原著中風趣的比喻變得艱澀而索然無味。而“讓強制屬性闕如或者示明抽象類別的例規(guī)約都是合法的。(it's legal to leave mandatory attributes empty or to show instance specifications of abstract classes.)”我不得不查看原著才明白。
盡管如此,書中(我是說原著)。還是有不少不錯的內(nèi)容的。于是做了些尋章摘句的工作。并附了英文原著。鍵盤摸得不熟,有打錯的擔待一下。謝謝!
泛化(generalization):
泛化的一個典型例子是涉及業(yè)務的個人客戶和公司客戶。個人客戶和公司客戶二者既有區(qū)別又有很多的類似之處??梢园杨愃浦幏湃胍粋€通用客戶類(超類型),它以個人客戶類及其公司客戶類為其子類型。對軟件來說,明顯的解釋是“繼承”:公司客戶類是客戶類的子類。
聚合與組合(aggregation and composition):
聚合是整體-部分關(guān)系。就如同說,一輛車以引擎和車輪為其兩部分。它聽起來很好,但困難的是什么是聚合與關(guān)聯(lián)的區(qū)別。UML包含了聚合,但幾乎沒有任何語義。(aggregation is the part-of relationship.it's like saying that a car has an engine and wheels as its parts. This sounds good, but the? difficult thing is considering what the difference is between aggregation and association. The UML included aggregation but with hardly any semantics.)
除聚合外UML具有另外定義的組合特性。點的一個實例可以是多邊形的部分也可以是圓心,但不能二者兼是。通則是,雖然一個類可以是多個其它類的成分,任一實例卻必須只能是一個擁有者的成分。類圖可以示明可能擁有者的多重類,但是,每個實例卻只能有單獨一個對象為其擁有者。(as well as aggregation,the UML has the more defined proerty of composition. an instance of Point may be part of a polygon or may be the center of a circle, but it cannot be both.The class diagram may show multiple classes of potential owners, but any instance has only a single object as its owner.)
組合是示明按值擁有的特性、值對象的特性,或者對其它特定成分具有強烈并稍有排它的擁有性等特性的好方法。聚合是完全沒有意義的。(Composition is a good way of showing properties that own by value, properties to value objects, or properties that have a strong and somewhat exclusive ownership of particular other components. Aggregation is strictly meaningless.)
分類與泛化(classification and generalization)
我常聽人把子類型稱為“是一(is a )”關(guān)系。我敦促你要提防這種思考方式。問題是“是一”這一短語可有不同的含義。
考察如下短語:
1.Shep 是一只牧羊犬。
2.牧羊犬是一只犬。
3.犬是一種動物。
4.牧羊犬是一屬(Breed).。
5.犬是一種(species)。
現(xiàn)在試圖把這些短語加以組合。如組合短語1 和2,便得"Shep 是一只犬";組合2,3得“牧羊犬是一種動物”;組合1、2、3得“Shep 是一種動物”。到目前為止,都很好。現(xiàn)在試1和4,便得“Shep 是一屬”。組合2、5 得“牧羊犬是一種”,這就不太好了。(?? Now try combining the phrases. If I combine phrases 1 and 2, I get "Shep is a Dog"; 2 and 3 taken together yield "Border Collies are Animals." And 1 plus 2 plus 3 gives me "Shep is an Animal." So far, so good. Now try 1 and 4: "Shep is a Breed." The combination of 2 and 5 is "A Border Collie is a Species." These are not so good.)
為什么我可以組合其中某些短語,而不可以組合別的短語?理由是,有些是分類(classification)(對象Shep是牧羊犬類型的一個實例),有些是泛化(generalization)(牧羊犬類型是犬類型的一個子類型)。泛化是傳遞的,分類則不然。我可以組合后接泛化的分類,反之則不然。(Why can I combine some of these phrases and not others? The reason is that some are classification—the object Shep is an instance of the type Border Collie—and some are generalization—the type Border Collie is a subtype of the type Dog. Generalization is transitive; classification is not. I can combine a classification followed by a generalization but not vice versa.)
我提出這一點是使你對“是一(is a)”謹慎對待。使用起子類不合適以及職責混淆。在這種情形,子類型更好的檢驗是如下一些短語:“犬是動物的種類”和“牧羊犬的每一實例都是犬的一個實例”。(? I make this point to get you to be wary of is a. Using it can lead to inappropriate use of subclassing and confused responsibilities. Better tests for subtyping in this case would be the phrases "Dogs are kinds of Animals" and "Every instance of a Border Collie is an instance of a Dog.")
附:英文原版可從fixdown下載。http://fixdown.com/soft/14631.asp
總結(jié)
以上是生活随笔為你收集整理的UML精粹--标准对象建模语言简明教程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Q:一个经典的helloworld程序需
- 下一篇: 一个机械系毕业生的感言