UML
Sections of this presentation were adapted from Martin Fowler UML Distilled: A Brief Guide to the Standard Object Modeling Language, 3rd Edition
History
Design notation of various kinds used since programming began:• Flow charts, Pseudo code, Structure
Diagrams …With advent of OO, many conflicting notations (1980s , 1990s)These notations were combined and unified (late 1990’s)UML extensively taught in universities(2000 - now).
UML: Unified Modeling Language An industry-standard graphical language for specifying, visualizing, constructing, and documenting the artifacts of software systems, as well as for business modeling.
The UML uses mostly graphical notations to express the OO analysis and design of software projects.
Simplifies the complex process of software designUML can be used to describe: the organization of a program how a program executes how a program is used how a program is deployed over a network …and more
What is UML?
Why UML for Modeling?
A diagram/picture = thousands wordsUses graphical notation to communicate more clearly than natural language (imprecise) and code(too detailed).Makes it easier for programmers and software architects to communicate.Helps acquire an overall view of a system.UML is not dependent on any one language or technology.UML moves us from fragmentation to standardization.
3 Ways to Use UML(Both forward & reverse engineering)1) Sketch e.g. at white board
1) Most common, quick and informal2) Communication & understanding
2) Blueprint1) Detailed design, implemented by programmer2) May have tools supporting diagramming
3) Programming Language1) Tools translate diagrams to executable code
During Software Lifecycle: UML Can Be Used at Various StagesAnalysis: OOA• What is system to do? What services is it to
provide? Provide requirements for designer.Design: OOD• What will be the parts & structure of the system?
How will they interact? Provide blueprint for programmer.
Programming: OOP
Classification of UML Diagrams
Structure1) Class diagram2) Component diagram (cmpts can be
independently purchased and replaced)
3) Component structure diagram4) Deployment diagram (what goes on what
machine & place)
5) Object diagram6) Package diagram (pkg = group of classes,
e.g. namespace)
There are 13 + Kinds of UML Diagrams
Classification of UML Diagrams(cont.)
Behavior7) Activity diagram (flow chart)
8) Use Case diagram (scenarios for use of system)
9) State Machine diagram10)Sequence diagram11)Communication diagram (data flow diagrams)
12) Interaction diagram (activity + sequence diagrams)
13)Timing diagram
Class Diagrams
Class diagrams
A class diagram is often all that is needed to describe a particular Design PatternA class diagram shows classes, interfaces, and their relationshipsWe’ll cover most of classes and interfaces, and a few of the most important relationshipsThe purpose of the class diagram is to show the types being modeled within the system.
10
"classifiers."
UML models types may include:
a classan interfacea data typea component.
Class
Class Name
Attribute : type
Operation (arg list) : return type
Abstract operation
Various parts are optional
Example UML Class Diagram
13
http://www.ibm.com/ -http://www.ibm.com/developerworks/rational/library/content/RationalEdge/sep04/bell/bell_fig5.jpg
Instance Specification(Object)
ObjectName: Class Name
Attribute : type
Operation (arg list) : return type
Abstract operation
Various parts are optional
An example of Class
Account_Name- Custom_Name- Balance
+AddFunds( )+WithDraw( )+PayInvoice( )
Name
Attributes
Operations
Class Example
class Checking {private:
char Customer_name[20]; float Balance; public: AddFunds(float); WithDraw(float); PayInvoice(float);
set_name(string);
get_name();
set_balance(float);
get_balance();
};
Relationships between Class Diagrams
Association -- a relationship between instances of the two classes. There is an association between two classes if an instance of one class must know about the other in order to perform its work. In a diagram, an association is a link connecting two classes.
Aggregation -- an association in which one class belongs to a collection. An aggregation has a diamond end pointing to the part containing the whole.
Generalization -- an inheritance link indicating one class is a superclass of the other. A generalization has a triangle pointing to the superclass.
17
Notation of Class Diagram: association
Bi-directional associationAssociations are assumed to be bi-directional e.g. Flight and plane notation:
Uni-directional associatione.g. Order and item notation:
Associations represent relationships between instances of classes .
Association: Multiplicity and Roles
University Person
1
1
*
*
Multiplicity
Symbol Meaning
1 One and only one
0..1 Zero or one
M..N From M to N (natural language)
* From zero to any positive integer
0..* From zero to any positive integer
1..* From one to any positive integer
0…8.. From zero to eight
8..14 From eight to fourteen
teacheremployer
RoleRole
“A given university groups many people; some act as students, others as teachers. A given student belongs to a single university; A given staff belongs to a single university; a given teacher may or may not be working for the university at a particular time.”
student
staff
*0..1
Notation of Class Diagram: Aggregation
AGGREGATION
Aggregation: expresses a relationship among instances of related classes.
Containee Classes
Flat
Rooms Storage Room
Example 1
Containee Classes
Car
Motor Wheels
Example2
AGGREGATION
41
Generalization (Inheritance)
Supertype
Subtype 1 Subtype 2
Generalization expresses a relationship among related classes. It is a class that includes its subclasses.
Generalization Example
http://www.ibm.com/developerworks/rational/library/content/RationalEdge/sep04/bell/bell_fig10.gif
Elements of Sequence Diagrams
Name: Class
New objectCreate
Message
Return
Delete
Self-call
Lifelines The dotted line that extends down the
vertical axis from the base of each object. Messages Labeled as arrows, with the arrowhead
indicating the direction of the call.
Activation bar The long, thin boxes on the lifelines are
method-invocation boxes indicting that indicate processing is being performed by the target object/class to fulfill a message.
Rectangle also denotes when object is deactivated.
Deletion (X)Object’s life ends at that point
Activation bar
Sequence Diagrams
Example for Sequence Diagram[Fowler]
We have an order and are going to invoke a command on it to calculate its price. To do that, the order needs to look at all the line items on the order and determine their prices, which are based on the pricing rules of the order line’s products. Having done that for all the line items, the order then needs to compute an overall discount, which is based on rules tied to the customer.
Example for Sequence Diagram[Fowler]
We have an order and are going to invoke a command on it to calculate its price. To do that, the order needs to look at all the line items on the order and determine their prices, which are based on the pricing rules of the order line’s products. Having done that for all the line items, the order then needs to compute an overall discount, which is based on rules tied to the customer.
Example Sequence Diagram
anOrder anOrderLine aProduct aCustomer
calculatePrice getQuantity
getProduct
getPricingDetails
getBasePrice
calculateDiscountsgetDiscountInfo
aProductFound
message
Participant Lifeline
ReturnActivation
Self call
MessageOperations
Object: Class
Message
USE CASES DIAGRAM
Use cases. A use case describes a sequence of actions that provide something of measurable value to an actor and is drawn as a horizontal ellipse.
Actors. An actor is a person, organization, or external system that plays a role in one or more interactions with your system. Actors are drawn as stick figures
Website Administration
Who manages the website?What type of different roles of admin and help desk have
Website Administration
gwww.uml-diagrams.or
Business Use Case Diagram for Airport Check-In and Security Screening
Business actors :?Business use cases ?PLEASE DISCUSS AND EXPLAIN WHY?
Business Use Case Diagram for Airport Check-In and Security Screening
Business actors :Passenger, Tour Guide, Minor (Child), Passenger with Special Needs (all playing external roles in relation to airport business.)
Business use cases are Individual Check-In, Group Check-In (for
groups of tourists), Security Screening
Baggage Check-in and Baggage Handling extend Check-In use cases, WHY?
Business Use Case Diagram for Airport Check-In and Security Screening
Activity Diagram
Activity diagram is used to show message flow from one activity to another.Activity Diagrams:Draw the activity flow of a system.Describe the sequence from one activity to another.Describe the parallel, branched and concurrent flow of the system.
http://www.sparxsystems.com/resources/uml2_tutorial/uml2_activitydiagram.html
An initial or start node Activity final node
Object
Decision Node Fork/Branch and Join Nodes
Merger Node