UML Modeling CS 247 Module 9 Scott Chen

  • Slides: 20
Download presentation
UML Modeling CS 247 Module 9 Scott Chen

UML Modeling CS 247 Module 9 Scott Chen

Assigned Readings Ø Martin Fowler, UML Distilled, ed. 3, Addition-Wesley Professional, 2004 • Electronic

Assigned Readings Ø Martin Fowler, UML Distilled, ed. 3, Addition-Wesley Professional, 2004 • Electronic text available from UW Library • Read as needed

Agenda for Module 9 Ø UML Class Diagrams • General Class Relationships Ø UML

Agenda for Module 9 Ø UML Class Diagrams • General Class Relationships Ø UML Object Model Diagrams Ø UML Sequence Diagrams

Section 1 UML Class Diagram and Class Relationships

Section 1 UML Class Diagram and Class Relationships

Unified Modeling Language Ø Definition - A collection of notations for representing different views

Unified Modeling Language Ø Definition - A collection of notations for representing different views of a software design Ø Application • • Documenting complex software design concepts, particularly OODs, in graphical representations Industry standard modeling method for large-scale system-level OOD optimizations Ø Structural Diagrams • Class Diagram, Object (Model) Diagram, component, composite structure, deployment, package Ø Behaviour Diagrams • State Diagram, Use-Case Diagrams, activity Ø Interaction Diagrams • Sequence Diagram, Timing Diagram, communication, interaction overview

UML Class Diagram Notation Ø Starting with Defining a Class Box • • •

UML Class Diagram Notation Ø Starting with Defining a Class Box • • • Class Name Attributes (data fields: types), initial values Operations (routines, signatures) – including public interface and private helper functions Scope Additional Attributes Customer - name: string {read. Only} - address: string + + Customer(name) name(): string {query} address. Is(newaddr: string): void Scope Keys + # public private protected static pure virtual {} additional attributes

UML Class Diagram Notation Ø Classes can be expressed at different levels of abstraction

UML Class Diagram Notation Ø Classes can be expressed at different levels of abstraction • Often chosen by the need for details Customer - name: string {read. Only} - address: string Customer name address birthday + + Customer(name) name(): string {query} address. Is(newaddr: string): void

The Class Relationships Ø UML deploys many class relationships, but we will cover the

The Class Relationships Ø UML deploys many class relationships, but we will cover the commonly used ones Ø Association • An association between two classes indicates that there exists a physical or conceptual link between objects of those classes. This link is often explicitly denoted in the diagram. • Unidirectional Association - denoted by solid line with arrow head Date day month year Person Driver Start Date Rental Agreement End Date Customer first. Name: string last. Name: string rents Rental Cars Association Name Vehicle make model colour VIN Role Name

The Class Relationships Ø Multiplicities • A notation indicating the constraint on the number

The Class Relationships Ø Multiplicities • A notation indicating the constraint on the number of allowable links in a UML relationship • Example § For each object x of class X, there must be at least p links of association R linking x to object of class Y § For each object y of class Y, there must be between m and n links of association R linking y to object of class X • No multiplicity annotation means that the multiplicity is unspecified (any number goes) • Bidirectional Association – denoted by solid line without arrowhead § Or can be denoted by a solid line with BOTH arrowheads X m. . n p. . * R Y

The Class Relationships Ø Some more examples for Association Implementation 0. . 2 A

The Class Relationships Ø Some more examples for Association Implementation 0. . 2 A A A 1 0. . 3 B B 2. . * * 3 B B B

The Class Relationships Ø Association Class • An association class represents link attributes §

The Class Relationships Ø Association Class • An association class represents link attributes § i. e. properties of the link, because they cannot be attributed to either of the end objects § Represented by dashed line with no arrowhead, linked in the middle of the associated link Person contestant * Competition * Performance time: Time place: int This is an Association Class, modeling data and relationships that are associated with a pair of objects

The Class Relationships Ø Aggregation • “A collection of” relationship – weaker form of

The Class Relationships Ø Aggregation • “A collection of” relationship – weaker form of “a part of” between collection and its members. § Denoted by straight line with hollow diamond head (at the aggregation end) • Members of an aggregation has their own identities outside of the aggregate § e. g. A dance team is an aggregation of dancers, but dancers are still dancers – with or without the team. • A part can be a member of more than one aggregate § e. g. A dancer can participate in different dance performances with different teams 0. . 1 Dance. Team * sub-team * 1. . * Dancer

The Class Relationships Ø Composition • “Compose of” relationship – stronger form of “a

The Class Relationships Ø Composition • “Compose of” relationship – stronger form of “a part of” between composite and its components. § Denoted by straight line with solid diamond head (at the composite end) • Components do NOT have an identity outside of the composite § e. g. A full-time Mc. Donald employee is no longer a Mc. Donald employee after resignation from the Mc. Donald corporation • A component belongs to at most one composite § e. g. A full-time employee must legally work for only one company to avoid conflict of corporation interests • The composite is responsible for creating and destroying its members § e. g. A corporation is responsible for all the processes for hiring and dismissing an employee Corporation size: int dept: List <string> 1 * Employee ID: int dept: string name: string 1. . * 1 Employee Benefit meal. Plan: string med. Plan: string vacation: int

The Class Relationships Ø Combined Example • On an i. Pod, individual songs for

The Class Relationships Ø Combined Example • On an i. Pod, individual songs for a ceremony is stored physically in the Ceremony Media Library, and Event Playlist are virtual collections of these songs for different stages of ceremony event (i. e. prelude, intro, main, interlude, outro, etc. ) Ceremony Media Library 1 * Ceremony Song * * Ceremony Event Playlist

The Class Relationships Ø Generalization • • Generalization defined the subtype relationship between a

The Class Relationships Ø Generalization • • Generalization defined the subtype relationship between a base class and its derived classes Every member of a derived class is a member of its base class Attributes and associations of the base classes are applied to all the derived classes Denoted by solid line with large hollow triangular arrowhead Transcript - GPA: float 1 + calc. GPA() Math Transcript + calc. GPA() Engineering Transcript + calc. GPA() 1 Student - name: string - ID: int

Section 2 Object Model and Sequence Diagram

Section 2 Object Model and Sequence Diagram

Object Model Diagram Ø Basically, it’s the runtime instance of the class diagram model

Object Model Diagram Ø Basically, it’s the runtime instance of the class diagram model • • Every object is an instantiation of a specific class Every link is an instantiation of a specific association Instance name can be optionally included as needed, but MUST be underlined along with the class name Instance attributes can be optionally provided in the diagram Student - firstname: string - lastname: string Class Diagram * firstname = “Peter” lastname = “Griffin” takes prefix: string number: int section: int term: string year: int firstname = “Brian” lastname = “Griffin” takes * Course - s 2: Student s 1: Student Object Diagram c 1: Course prefix = “CS” number = 247 section = 001 term = “Spring” year = 2020

Sequence Diagram Ø A graphical model of communication events between objects, as exhibited in

Sequence Diagram Ø A graphical model of communication events between objects, as exhibited in one execution trace Instance Box (can be objects, systems, actors, etc. ) Sequence Start: event, method call Time : Purchase. Order print. Receipt() : Product print() execution occurrence Synchronous (Blocking) calls in solid lines print() Return Message return lifeline Asynchronous (Non-blocking) calls in dashed lines

Summary

Summary

Summary Ø UML Class Diagram (and Object Diagram) • Key Relationships – Association, Aggregation,

Summary Ø UML Class Diagram (and Object Diagram) • Key Relationships – Association, Aggregation, Composition, Generalization • Key Features – Multiplicities, Association Class • How to convert Class Diagram into Object Diagram Ø UML Sequence Diagram • Key Features – Temporal interaction sequence, Synchronous vs. Asynchronous events Ø Some UML Drawing Tools • • Visio Omni. Graffle (Mac Only) UMLet (Open Source, All Platform – http: //www. umlet. com) More demo coming in tutorial