UML COSC 4354 1
UML Is Not a Methodology UML is an acronym for Unified Modeling Language UML is a language A language is simply a tool for communication and exchanging ideas UML is a notation, not a methodology It can be used in conjunction with any methodology UML has become a world standard Every software engineer today needs to know UML 2
System Views Any system can be viewed from three different angles: Static View: describes the structure of the system; the different components of the system Ex: Class diagram Functional View: describes the functionality of the system from the user s view, what the system offers to external entities. Ex: Use Case diagram Dynamic View: describes how the system behaves under different scenarios. Ex: Seuence diagram 3
Class Diagrams A class diagram depicts classes and their interrelationships Here is a simple possible component of a class diagram 4
Class Diagrams (contd) Class diagram showing more details of Bank Account Class Add as many details as appropriate Attributes and Operations 5
Class Diagrams: Visibility Prefixes (contd) UML visibility prefixes (used for information hiding) Prefix + indicates that an attribute or operation is public Visible everywhere Prefix denotes that the attribute or operation is private Visible only in the class in which it is defined Prefix # denotes that the attribute or operation is protected Visible either within the class in which it is defined or within subclasses of that class 6
Class Diagrams: Visibility Prefixes (contd) Example: Class diagram with visibility prefixes added Attribute accountbalance is visible only within the Bank Account Class Operations deposit and withdraw are accessible from anywhere within the software product 7
Aggregation Example: A car consists of a chassis, an engine, wheels, and seats 8
Multiplicity Example: A car consists of one chassis, one engine, 4 or 5 wheels, an optional sun roof, zero or more fuzzy dice hanging from the rearview mirror, and 2 or more seats 9
Multiplicity (contd) The numbers next to the ends of the lines denote multiplicity The number of times that one class is associated with the other class The line connecting Chassis Class to Car Class The 1 at the part end of the line denotes that there is one chassis involved The 1 at the whole end denotes that there is one car involved Each car has one chassis, as reuired Similar observations hold for the line connecting Engine Class to Car Class 10
Multiplicity (contd) If the exact multiplicity is known, use it Example: The 1 that appears in 8 places If the range is known, use the range notation Examples: 0..1 or 4..7 If the number is unspecified, use the asterisk Example: * If the range has upper limit unspecified, combine the range notation with the asterisk notation Example: 2..* 11
Composition Aggregation example: Every chess board consists of 64 suares This relationship goes further It is an instance of composition, a stronger form of aggregation 12
Composition (contd) Aggregation Models the part whole relationship Composition Also models the part whole relationship but, in addition, Every part belongs to only one whole, and If the whole is deleted, so are the parts Example: A number of different chess boards Each suare belongs to only one board If a chess board is thrown away, all 64 suares on that board go as well 13
Composition (contd) Composition is depicted by a solid diamond 14
Generalization (contd) Every instance of Investment Class or its subclasses has an attribute investmenttype (the discriminator) This attribute can be used to distinguish between instances of the subclasses 15
Association General form of a relationship An example of association: A radiologist consults a lawyer The optional navigation triangle shows the direction of the association 16
Developing a Class Diagram Identify your candidate classes A class is a thing which has behavior, state, and identity. Booch Reflected in operations, attributes, and title, respectively. Identify all relationships between the different classes Revisit your classes Do you need to add? Do you need to omit? Identify the attributes and operations of every class 17
Functional View: Use-Case Diagrams A use case is a model of the interaction between Actors: External users of a software product and More precisely, an actor is a user playing a specific role The software product itself A use-case diagram is a set of use cases Every use case usually has its own use case diagram 18
Use Case Diagrams First, identify the external entities that may interact with the system; actors. Second, identify the different functions that an actor can use or be used by the system to accomplish; use cases. Third, expand every use case to its functional components in a separate use case diagram Last, describe every use case in a textual form Identification Summary: a title or a number for the use case + one line summary of what this use case offers Flow of Events: Describe the main successful scenario of this use case Describe possible errors Describe the preconditions and postconditions 19
Exercise Develop a Use Case diagram for an ATM system with the following specifications Distribution of money to every holder of an ATM or credit card via a card reader and a cash dispenser Consultation of account balance, cash and check deposit facilities for bank customers who hold an ATM card from the ATM s owner bank All transactions are made secure by a Visa Authorization System and the Bank Information System It is sometimes necessary to refill the dispenser, maintain the ATM etc. 20
Actors Bank Customer Cardholder Bank IS Visa AS Maintenance Operator 21
Use Cases Cardholder Withdraw money Bank Customer Withdraw money Consult balance Deposit cash Deposit checks Maintenance Operator Refill dispenser Retrieve checks Fix problems 22
Use Cases (cont.) Visa Authorization System (secondary) Withdraw money Bank IS (secondary) Withdraw money Consult balance Deposit cash Deposit checks 23
Use Cases: Textual Description Title: Check Balance Summary: This use case allows a bank customer to check his/her balance on the account associated with the ATM card used. Actors: Bank Customer, Bank IS Preconditions: ATM is working properly and connected to the Bank IS No card in the reader 24
Use Cases: Textual Description (cont.) Flow of Events: Main Successful Scenario The bank customer inserts the card in the reader The ATM verifies that the card inserted is indeed a smartcard The ATM asks the customer to enter the card s PIN. Alternative Scenarios: A1: Incorrect PIN The ATM informs the bank customer that the PIN is incorrect and asks him to reenter it. 25
Use Cases: Textual Description (cont.) Postconditions: Same as preconditions 26
Interaction Diagrams Dynamic View Interaction diagrams show how objects interact with one another UML supports two types of interaction diagrams Seuence diagrams Collaboration diagrams Seuence diagrams model the interactions involved in the execution of An operation (usually associated with classes) A use case s scenario 27
Seuence Diagrams 28