230 likes | 459 Views
Class and Object Diagrams. Class diagram – basic syntax. Association name. Class name. Class name. Attributes. Attributes. Methods. Component. aggregation. Aggregate. Class name. specialization. Class name. This is a subclass. Attributes. Methods. comments.
E N D
Class diagram – basic syntax Association name Class name Class name Attributes Attributes Methods Component aggregation Aggregate Class name specialization Class name This is a subclass Attributes Methods comments C-S 546
Class diagram - semantics • a class icon must have a class name. Optionally, it can have attributes and/or methods. • attributes and methods are strings and will not be validated by the modeling tools. • attributes can be specified by their names or by <name, type> pairs. • methods can be specified by their names or partial signature or complete signature. • additional qualifiers for methods (such as public, private or protected) can also be specified. • UML has specific symbols for these qualifiers C-S 546
Class diagram – semantics (continued) • Comments can be included in any diagram with a stripped rectangle • The dotted line from the comment box is important to indicate which portion of the diagram is explained in the comments • When showing aggregation relationship, the aggregate (the one near the diamond edge) must include an attribute whose type is the component class C-S 546
Details of a class icon Account Initial value - Account number : Integer - Balance : Real - Overdraft : Boolean = true • + GetAccountId () • # UpdateBalance (sign : Sign, amt : Integer) • ~ ReturnBalance () : Real • ChangeOverdraft () • + public • private • # protected • ~ visible within the package C-S 546
An abstract class Polygon {abstract, author = Kasi, last modified = Oct 2002} <<constructor>> + Polygon(List of Vertex vertices) <<query>> #area () : Real C-S 546
Object Diagram act : Account : Account Account number = 1256 Balance = 0 Overdraft = false act : Account Various representations of an account object C-S 546
Object diagram (continued) rect : Rectangle topLeft : Coordinate x = 100.0 y = 110.0 bottomRight : Coordiante x = 570.0 y = 390.0 Composite objects - aggregation C-S 546
Association –syntax Association label Direction of association uses customer Account User 1 n Account number Balance Overdraft Manager 1 cardinality Get accountID () Update balance() Return balance() Role names {xor} uses Unary association Corporate Account n C-S 546
Association - Semantics • every association is expected to be labeled • UML does not require a name for an association • direction of an association, cardinality, role name are all optional • for unary associations, role names must be included • representations of cardinality • 0, 1, * (zero or more), n..m (values in the range between n and m both inclusive) • a constraint may be [optionally] placed between two associations • see the example in the previous slide that asserts an Exclusive OR relationship between the associations C-S 546
Association – Semantics (continued) • When a subclass specializes a superclass, it also inherits all associations between the superclass and other classes • In the current example, the association “uses” between “User” and “Account” is also inherited by “Corporate Account” • The diagram shows this association explicitly but it is not necessary to include it in the diagram C-S 546
Association with qualifiers uses Account User 1 n Account number Balance Overdraft Account number Get accountID () Update balance() Return balance() Qualifier attribute Qualifier Corporate Account C-S 546
Association - Qualifiers • Qualifiers can be attached to a “1-many” association • It is rectangle attached to the “many” end of the association • A qualifier is a collection of variables whose values uniquely identify an instance at the “many” end of the association • In the example, an account number uniquely identifies an account in a collection of accounts • Qualifier is part of the association, and not necessarily be a part of the classes participating in the association C-S 546
Association Class User Account Transaction Job Employee Salary C-S 546
Association Class - semantics • a piece of information that belongs to both classes in an association is put into a separate class called “association class” • association class is a dependent class that depends on the other two classes in the association • cannot exist independently • object of an association class must refer to objects of the other two classes in the association • Example: A “Transaction” object depends on a “User” object and on an “Account” object. C-S 546