Chapter 16 UML类图 ●●●●● ●●●● ●●。●●
Chapter 16 UML类图
●●●●● ●●●● 简介 ●●● ●●● ●●●● ●UML用类图表示类,接口及其关联 类图用于静态对象建模 类图和概念图之间的关系 Domain model Register 1 Captures conceptual perspective is Complete: Boolean /total Register Sale Design Model time is Complete: Boolean DCD: software end saleo currentSale/total perspective enterItem(.) make Payment(.) makeLineltem()
简介 ⚫ UML用类图表示类,接口及其关联 ⚫ 类图用于静态对象建模 ⚫ 类图和概念图之间的关系 Register ... endSale() enterItem(...) makePayment(...) Sale time isComplete : Boolean /total makeLineItem(...) Register ... Sale time isComplete : Boolean /total Captures 1 1 1 Domain Model conceptual perspective Design Model DCD; software perspective currentSale
表示法(文本格式) SuperclassFoo used to distinguish the package name from the class name ●●●●● SuperclassFoo( abstract ●●●● unofficially, the second alternative class OrStaticAttribute: Int Is common ●●● ●●● 3 common compartments privateAttribute ●●●● ssumed Private Attribute 1. classifier name Initialized Attribute: Bool true aCollection: VeggieBurger[ o java. awt: Font 2. attributes attribute Legally BeNull String [0.11 finalConstantAttribute: Int=5(readonly 1 java. awt. Font /derivedAttribute 3. operations plain: Int =0 readonly classorStaticMethodo bold: Int =1 readOnly y publicMethodo assumedPublicMethodo style: Int =0 an interface protectedMethodo keyword getFont(name: String): Font packageVisibleMethod getName0: String methodWithParms(parm1: String parma: Float methodReturns Something(: Veggie Burger Interface》 methodThrows Exception( exception IOException Runnable abstractMethodo abstractMethod20 abstract) //alternate runo finalMethodo( leaf)//no override in subclass ynchronizedMethodoi guarded y interface subclassing Subclass Foo Purchaseorder association with ellipsis".means there may be elements, but not shown multiplicities blank compartment officially means "unknown but as a convention will be used to mean "no members
表示法(文本格式) java.awt::Font or java.awt.Font plain : Int = 0 { readOnly } bold : Int = 1 { readOnly } name : String style : Int = 0 ... getFont(name : String) : Font getName() : String ... «interface» Runnable run() - ellipsis “…” means there may be elements, but not shown - a blank compartment officially means “unknown” but as a convention will be used to mean “no members” SubclassFoo ... run() ... SuperclassFoo or SuperClassFoo { abstract } - classOrStaticAttribute : Int + publicAttribute : String - privateAttribute assumedPrivateAttribute isInitializedAttribute : Bool = true aCollection : VeggieBurger [ * ] attributeMayLegallyBeNull : String [0..1] finalConstantAttribute : Int = 5 { readOnly } /derivedAttribute + classOrStaticMethod() + publicMethod() assumedPublicMethod() - privateMethod() # protectedMethod() ~ packageVisibleMethod() «constructor»SuperclassFoo( Long ) methodWithParms(parm1 : String, parm2 : Float) methodReturnsSomething() : VeggieBurger methodThrowsException() {exception IOException} abstractMethod() abstractMethod2() { abstract } // alternate finalMethod() { leaf } // no override in subclass synchronizedMethod() { guarded } 3 common compartments 1. classifier name 2. attributes 3. operations interface implementation and subclassing Fruit ... ... PurchaseOrder ... ... 1 association with multiplicities dependency officially in UML, the top format is used to distinguish the package name from the class name unofficially, the second alternative is common order an interface shown with a keyword
图形格式 ●●●●● ●●●● ●●● (Rational Software Modeler) ●●● ●●●● AC卫ass 口 privateAttribute o publicAttribute 工 nteger o staticattribute ● lOAn10 peration St112 o abstractOperation (
图形格式 (Rational Software Modeler)
●●●●● ●●●● UML中的类型 ●●● ●●● ●●●● 类 接 ●枚举 ●数据类型 inter face》 enuunerat1on》 Person Iterator 运年级 o name: String o一年级 e haslEt ( o二年级 o三年级 (primitive) 9 Date
UML中的类型 ⚫ 类 ⚫ 接口 ⚫ 枚举 ⚫ 数据类型
●●●●● ●●●● 属性表示:文本和关联线 ●●● ●●● ●●●● 对数据类型对象使用属性文本,对引用对象使用关联线 Register Sale applying the guideline to show attributes as id: Int time: date time attribute text versus as currentsale association lines Register has THREE attributes Store 1. id 2. currentSale address: Address 3. location location phone: PhoneNumber
属性表示:文本和关联线 Register id: Int ... Sale time: DateTime ... 1 applying the guideline to show attributes as attribute text versus as association lines Store address: Address phone: PhoneNumber ... 1 Register has THREE attributes: 1. id 2. currentSale 3. location currentSale location 对数据类型对象使用属性文本,对引用对象使用关联线
●●●●● ●●●● 属性表示:混合文本和关联线 ●●● ●●● ●●●● using the attribute Register text notation to indicate Register has o currentSale: Sale a reference to one Sale instance OBSERVE: this style Register Sale visually emphasizes the connection between these classes o currentSale using the association notation to indicate Register has a reference to one Sale instance thorough and Register unambiguous, but some currentsale: Sale people dislike the possible redundancy currentsale
属性表示:混合文本和关联线 Register ... ... Sale ... ... 1 Register currentSale : Sale ... Sale ... ... using the attribute text notation to indicate Register has a reference to one Sale instance using the association notation to indicate Register has a reference to one Sale instance OBSERVE: this style visually emphasizes the connection between these classes currentSale Register currentSale : Sale ... Sale ... ... 1 thorough and unambiguous, but some people dislike the possible redundancy currentSale
●●●●● ●●●● 属性表示:导航箭头 ●●● ●●● ●●●● thorough and Register Sale unambiguous, but some current sale: Sale people dislike the possible redundancy currentsale Company Person
属性表示:导航箭头 Register currentSale : Sale ... Sale ... ... 1 thorough and unambiguous, but some people dislike the possible redundancy currentSale Company Person 1 *
●●●●● ●●●● 属性表示:多重性 ●●● ●●● ●●●● zero or more many one or more 1.40 one to 40 5 exactly 5 3,5,8 exactly 3, 5, or 8
属性表示:多重性 zero or more; "many" one or more one to 40 exactly 5 T T T T * 1..* 1..40 5 T 3, 5, 8 exactly 3, 5, or 8
●●●●● ●●●● 属性表示:角色名 ●●● ●●● ●●●● Employer Company Person Employee
属性表示:角色名 Company Person Employer Employee