Agenda
General Software Modeling General UML UML Diagrams
Resources
These slides are a mashup from different sources, i.e. all the credits go to them.. Sommervilles book: Software Engineering lecture slides Genix UML tutorial: http://www.genixcorp.com/ba/uml.ppt Tom Hortons Object-Oriented Analysis and Design lecture material: http://www.cs.virginia.edu/~horton/cs494/slides/ Amblers book: The Object Primer D. Schmidts (Boeing example and design patterns part) tutorial : http://www.cs.wustl.edu/~schmidt/tutorialspatterns.html UML for Systems Engineering,:watching the wheels, 2nd Ed. , Jon Holt, IET Professional Applications of Computing Series, 2007.
SWE513 Spring 2010 - UML tutorial Part I
OO methods provide a set of techniques for analyzing, decomposing, and modularizing software system architectures In general, OO methods are characterized by structuring the system architecture on the basis of its objects (and classes of objects) rather than the actions it performs
OO enhances key software quality factors of a system and its constituent components
In general, systems evolve and functionality changes, but objects and classes tend to remain stable over time
SWE513 Spring 2010 - UML tutorial Part I 6
UML
Is a language. It is not simply a notation for drawing diagrams, but a complete language for capturing knowledge (semantics) about a subject and expressing knowledge (syntax) regarding the subject for the purpose of communication.
It is the result of unifying the information systems and technology industrys best engineering practices (principals, techniques, methods and tools).
SWE513 Spring 2010 - UML tutorial Part I 7
UML (contd)
Unified because it
Combines main preceding OO methods (Booch by Grady Booch, OMT by Jim Rumbaugh and OOSE by Ivar Jacobson)
Modeling because it is
Primarily used for visually modeling systems. Many system views are supported by appropriate models
Language because
It offers a syntax through which to express modelled knowledge
UML Elements
UML (again)
What it is
A language for capturing and expressing knowledge A technology for visual development modeling A set of well-founded guidelines A milestone generator A popular (therefore supported) technology
What it is not
A visual programming language or environment A database specification tool A development process (i.e. an SDLC) A silver bullet A quality guarantee
SWE513 Spring 2010 - UML tutorial Part I 10
UML (again)
The UML is a standard representation devised by the developers of widely used object-oriented analysis and design methods. It has become an effective standard for object-oriented modelling. Notation
Object classes are rectangles with the name at the top, attributes in the middle section and operations in the bottom section; Relationships between object classes (known as associations) are shown as lines linking objects; Inheritance is referred to as generalisation and is shown upwards rather than downwards in a hierarchy.
11
UML Diagrams
Functional Requirements
Use-Case (relationship between actors and system functions) Class (static class structure) Object (same as class - only using class instances i.e. objects) Package (logical grouping of classes) Component (code structure) Deployment/Implementation (mapping of software to hardware) State (states of objects in a particular class) Sequence (Object message passing structure) Collaboration/Communication (same as sequence but also shows context - i.e. objects and their relationships) Activity (sequential flow of activities i.e. action states)
SWE513 Spring 2010 - UML tutorial Part I 12
Structure
Behavior
13
14
Components
Actor Goals Relationships
Use-case Relationship
Uses Consumes Generalization - Specialization Extends - Inherits
15
Requirements
16
Specification Documents
Steven McConnell (IEEE Software, Oct. 2000) says any of the following are called requirements document:
Half-page summary of software product vision Two-page key features list 50-page list of details about end-user requirements (he calls this a function-requirements document) 250-page exhaustive list of details about screens and GUI, input and input conditions, all system states and state changes, all persistent data, etc.
This 4th item is what we usually mean by a Software Requirements Specification (SRS) document
17
Vision Statement
You have been contracted to develop a computer system for a university library. The library currently uses a 1960s program, written in an obsolete language, for some simple bookkeeping tasks, and a card index, for user browsing.You are asked to build an interactive system which handles both of these aspects online.
18
Use Case:
A sequence of actions a system performs to yield an observable result of value to a particular actor. Stevens/Pooley: A task which an actor needs to perform with the help of the system
Actor:
Someone or something outside the system that interacts with the system A user of the system in a particular role
20
Use Cases
21
Actors
BookBorrower JournalBorrower Browser (person who browses, not SW) Librarian Borrow copy of a book Reserve a book Return copy of book Borrow journal Browse Update Catalog
SWE513 Spring 2010 - UML tutorial Part I 22
Use Cases
23
Informal Scenarios
an informal narrative story, simple, natural, personal, not generalisable
Use cases
24
26
Use case number or id: Use case title: Actors: Text description (a few sentences) Preconditions (if applicable): Flow of Events: Basic path:
1.First step 2.Second step 3.etc
Alternative Paths:
Name and short description (in words) of first alternative path/scenario. Name and short description (in words) of 2nd alternative path/scenario. etc.
27
28
29
Step 8.
If no potential dates are found, then 8.1 The system displays a suitable message. 8.2 The system returns to step 5.
30
Departmental member
31
4. search calendars for suitable dates 5. suggest potential dates 7. book meeting
32
33
Meaning:
The source use case always includes the actions specified in the target use case
Meaning:
The target use case my include the behavior of the source use case
SWE513 Spring 2010 - UML tutorial Part I 34
Back to business...
Enough on Requirements-Use Cases couple, back to core UML....
35
Functional Requirements
Use-Case (relationship between actors and system functions) Class (static class structure) Object (same as class - only using class instances i.e. objects) Package (logical grouping of classes) Component (code structure) Deployment/Implementation (mapping of software to hardware) State (states of objects in a particular class) Sequence (Object message passing structure) Collaboration/Communication (same as sequence but also shows context - i.e. objects and their relationships) Activity (sequential flow of activities i.e. action states)
SWE513 Spring 2010 - UML tutorial Part I 36
Structure
Behavior
37
38
39
Reader Af filiation
40
Multiple inheritance
Rather than inheriting the attributes and services from a single parent class, a system which supports multiple inheritance allows object classes to inherit from several super-classes. This can lead to semantic conflicts where attributes/services with the same name in different super-classes have different semantics. Multiple inheritance makes class hierarchy reorganisation more complex.
41
Multiple inheritance
Book Author Edition Pub lication da te ISBN Voice recording Speak er Duration Recording da te
42
Object aggregation
An aggregation model shows how classes that are collections are composed of other classes. Aggregation models are similar to the part-of relationship in semantic data models.
43
Object aggregation
44
45
Earlier we modeled requirements using... Class Diagrams: Known as the Conceptual Model
Sometimes known as the logical model. Classes represent domain-level entities. (E.g. things in the users world.)
Thus no classes for implementation-level things.
Associations model domain-level relationships. (E.g. user-understood relationships between things in the users world.)
Usually dont show navigation on associations
SWE513 Spring 2010 - UML tutorial Part I 46
47
Compare different possible design solutions Evaluate efficiency, ease of modification, maintainability, etc
SWE513 Spring 2010 - UML tutorial Part I 48
Several UML notations provide various views of a design Class diagrams: Possibly created at two different levels of abstraction for design:
Specification level: Classes model types, and we focus solely on interfaces between software modules Implementation level: Think of this as a true software blueprint. We can go directly to code from this model.
Sequence diagrams and Collaboration diagrams
49
Sequence diagrams
Objects will be variables implemented in code Messages are operations (e.g. C++ member functions) applied to objects Sequence diagrams thus show how a sequence of operations called between a set of objects accomplishes a larger task Sequence diagrams for a particular scenario help identify operations needed in classes They also allow us to verify that a design can support requirements (e.g. a use-case scenario)
SWE513 Spring 2010 - UML tutorial Part I 50
State diagrams
Models how a particular object responds to messages according to its state For a single object, show states and transitions between states Transitions may be conditional based on a guard condition May show an action an object takes on transition, or also activity carried out within a state Occasionally used to model a systems or subsystems behavior (not just one objects)
SWE513 Spring 2010 - UML tutorial Part I 51
Packages
A simple notation that groups classes together Possible to use this to show contents of a subsystem
Show dependencies between packages Show visibility of classes between packages
Component Diagrams
Models physical modules of code (e.g. files, DLLs, physical databases)
SWE513 Spring 2010 - UML tutorial Part I 52
Design Process
There are many different approaches to design, but here is something typical. First, create a model of the high-level system architecture
Next, use the conceptual class model to build a design-level class model or models Also, model dynamic behavior using interaction diagrams.
53
Well use sequence diagrams with objects from the implementation-level class model
Sequence diagrams show how design-level objects will carry out actions to implement scenarios defined as part of use-case analysis Messages between objects are member-function calls between objects Important: Only member-function calls are shown, but other language statements (e.g. assignments) are executed between calls (of course).
SWE513 Spring 2010 - UML tutorial Part I 54
Data manager classes. E.g. collection objects that were simply associations before Facilitator or helper classes that assist with complex tasks (e.g. ObservableComponent) Factory classes that assist in creating new objects Classes to implement other design patterns
57
Direction matters!
Persistence Classes
Persistent Store(s)
SWE513 Spring 2010 - UML tutorial Part I 58
Controller/Process classes
implement business logic, collaborations between business objects and/or other controller
Persistence classes
How to store, retrieve, delete objects Hides underlying data stores from rest of system
System classes
Wrap OS-specific functionality in case that changes
SWE513 Spring 2010 - UML tutorial Part I 59
Controller/Process Layer
60
More on Controllers
Why not just put business logic into the Domain class?
Business rules change. We want domain classes to be reusable. In UI class? Then must use that UI to carry out this process. (Too tightly coupled.)
Violates a principle of the OO approach! Yes, but is this always the best solution?
Data and behavior kept together!
DVDs and DVD players -- why not one unit? Cameras and film vs. disposable cameras
Consider coupling, change, flexibility Controller classes are an example of the Mediator design pattern Mediator or control classes might grow to become god classes
too much control, or too centralized
SWE513 Spring 2010 - UML tutorial Part I
62
Implementing Associations
How associations are implemented is affected by multiplicity. Where they are implemented depends on navigability.
In one class or in both? Until now we may not have worried about direction of associations. Thats fine! Often navigability cannot be determined until design phase. Often it changes as we do more design. In prototypes we often keep links bidirectional for flexibility.
63
64
OneOne-Way Associations
If an association should just be navigable in just one direction, use the arrow form of the UML association in your class diagram.
In UML no arrows means two-way or bi-directional.
Consider using association name or role name from the class diagram to name this attribute
65
If the multiplicity is 1 or 0..1 then the attribute would be a pointer to an object of the target class
E.g. attribute in class Phone: E.g. 3, 0..3, 2..4 selectedLine: Line*
If the multiplicity is many but has a fixed maximum, then use array of pointers (or objects)
If no fixed maximum, e.g. 1..* or 0..*, then use a collection object as an attribute that stores an arbitrarily large number of pointers or objects For qualified associations use a hash-table or map object to associate key with target object
66
Examples using the C++ standard library... A vector class is like an array with no maximum capacity Other C++ classes might be appropriate too: set, list Note: Your team might agree not to show the * to indicate pointers. Conventions vary.
SWE513 Spring 2010 - UML tutorial Part I 67
Option Two:
In one class, Class A, implement just like oneway (see above) to access Class B objects. In second class, Class B, write an operation that uses some kind of search of all objects of Class A to find the one that points back to the current B object.
Why? Saves space if access from B to A is very rare But, requires there to be some place where all objects of Class A are stored
SWE513 Spring 2010 - UML tutorial Part I 69
70
Person3
SWE513 Spring 2010 - UML tutorial Part I
Company2
71
72
Association Classes
Recall that qualified associations really mean that the link between two objects has an attribute Often associations are first-class things
They have a life-time, state, and maybe operations Just like objects!
Association classes
Same name as the association because... They represent the same thing!
SWE513 Spring 2010 - UML tutorial Part I 73
74
Hotel Reservation
*
3
Play
Pla n ysI
2
s at
City
Referee
*
Assignment
*
Game
76
If one-to-many, then same choices as one-toone, but do this for the object on the many end If many-to-many, you need a separate class with an object instantiated for each link
SWE513 Spring 2010 - UML tutorial Part I
Put attributes and operations inside either object Or, put them in a separate class thats linked to either object
77
AssocClass
78
This forms a 3-tuple for each conceptual-level link between a pair of ClassA and ClassB objects
79
80
81
Agenda
Some more on UML (especially interaction diagrams) Some case studies/examples UML tools: Eclipse UML plugins, MS Visio, Rational Rose, others Project announcement
83
Functional Requirements
Use-Case (relationship between actors and system functions) Class (static class structure) Object (same as class - only using class instances i.e. objects) Package (logical grouping of classes) Component (code structure) Deployment/Implementation (mapping of software to hardware) State (states of objects in a particular class) Sequence (Object message passing structure) Collaboration/Communication (same as sequence but also shows context - i.e. objects and their relationships) Activity (sequential flow of activities i.e. action states)
SWE513 Spring 2010 - UML tutorial Part I 84
Structure
Behavior
85
Sequence Diagram -1
86
87
88
89
90
Activity Diagram
91
Activity diagram showing behaviour of a thought process of how to play chess (badly)
SWE513 Spring 2010 - UML tutorial Part II 92
Sequence Diagram - 4
93
sequence diagram
94
Collaboration Diagram - 2
95
96
So far sequence diagrams model interactions between implementation-level objects Also, can be used to model use cases
Actor(s) interacting with the System
Most useful if more than one Actor Messages are used informally here
97
Maybe on dashed return arrow, or On message call: n = getName() Again, note returns not always explicitly drawn
SWE513 Spring 2010 - UML tutorial Part II 98
Notes on Messages
99
100
101
Classes Phone: a persons telephone Line: a number associated with a phone Lines are busy, calls are made on lines, etc. Connection: dynamically created, represents an active call between lines Switch: a phone switch is a computer system that manages phones, lines and connections Console: a terminal attached to the switch Simulator: were writing a simulation!
102
Switch manages other objects More than one Phone may be linked to one line
Like for office secretary, boss
103
0..*
0..*0..*
selected
104
Scenario
A normal call
Phone1 chooses Line 1 and picks up Phone 1 dials number for Phone2 Phone 2 rings Phone 2 picks up Call completed and the two people talk Phone 2 hangs up Phone 1 is disconnected Phone 1 hangs up
SWE513 Spring 2010 - UML tutorial Part II 105
Switch
name : string
1
controls
1
manages
1
manages
1
manages
0..* Phone
state : PhoneState name : string
0..*
0..*
0..* Connection
id : int state : ConnState duration : int disconnect(l : Line) : void addLine(l : Line) : void
0..*
selectLine(num : int) : void pickup() : void hangup() : void ring() : void dial(num : int) : void addLine(l : Line) : void
incomingCall(c : Connection) : void hungUp(p : Phone) : void linkedLines 1..* pickedUp(p : Phone) : void 0..* addPhone(p : Phone) : void
onConnection 1..*
2..* 1
0..1
106
pickedUp(p2)
hangup() hungup(p1)
107
Functional Requirements
Use-Case (relationship between actors and system functions) Class (static class structure) Object (same as class - only using class instances i.e. objects) Package (logical grouping of classes) Component (code structure) Deployment/Implementation (mapping of software to hardware) State (states of objects in a particular class) Sequence (Object message passing structure) Collaboration/Communication (same as sequence but also shows context - i.e. objects and their relationships) Activity (sequential flow of activities i.e. action states)
SWE513 Spring 2010 - UML tutorial Part II 108
Structure
Behavior
109
110
111
The next part is from Patterns, Frameworks and Middleware: Their Synergestic Relationships tutorial by D. C. Schmidt: http://www.cs.wustl.edu/~schmidt/tutorialspatterns.html (a very important source for serious distributed networked software design and development)
112
Design pattern: a description of a problem that reoccurs and an outline of an approach to solving that problem
Generally domain, language independent Also, analysis patterns
Framework:
A partially completed design that can be extended to solve a problem in a domain
Horizontal vs. vertical
113
Idioms
Design patterns
Scoped locking
Active Object, Bridge, Proxy, Wrapper Faade, & Visitor Half-Sync/HalfAsync, Layers, Proactor, PublisherSubscriber, & Reactor Optimize for common case, pass information between layers
Architectural patterns
114
Mission Computer
Data Links
Weapon Management
Radar Weapons
Mission Computing Services Middleware Infrastructure Operating System Networking Interfaces Hardware (CPU, Memory, I/O)
architecture for Boeing military aircraft, e.g., operating systems, & middleware F-18 E/F, 15E, Harrier, UCAV Used as Open Experimentation DRE system with 100+ developers, 3,000+ Platform (OEP) for DARPA IXO PCES, software components, 3-5 million lines of MoBIES, SEC, MICA programs 115 C++ code
Operating System
Networking Interfaces Hardware (CPU, Memory, I/O)
COTS & Standards-based Middleware Infrastructure, OS, Network, & Hardware Platform
Real-time CORBA middleware services VxWorks operating system VME, 1553, & Link16 PowerPC
116
Mission Computing Services Middleware Infrastructure Operating System Networking Interfaces Hardware (CPU, Memory, I/O)
117
Mission Computing Services Middleware Infrastructure Operating System Networking Interfaces Hardware (CPU, Memory, I/O)
118
Mission Computing Services Middleware Infrastructure Operating System Networking Interfaces Hardware (CPU, Memory, I/O)
Operator
Real World Model
Configurable for product-specific component assembly & deployment environments Model-based component integration policies
Avionics Interfaces
Infrastructure Services
119
120
Pattern name
A vocabulary of patterns is beneficial
Problem
When to apply the pattern, what context. How to represent, organize components Conditions to be met before using
Solution
Design elements: relationships, responsibilities, collaborations A template for a solution that you implement
Consequences
Results and trade-offs that result from using the pattern Needed to evaluate design alternatives
121
Reusable code, class libraries, etc. (At a higher level) Do not require complex implementations Always the best solution to a given situation Simply a good thing to do
122
The GoF (Design Patterns: Elements of Reusable Object-Oriented Software) defined a standard format
Generally followed Not just a UML diagram!
124
The class has a static variable called theInstance (etc) The constructor is made private (or protected) Clients call a public operation getInstance() that returns the one instance This may construct the instance the very first time or be given an initializer
125
new MySingleton();
private MySingleton() { // constructor } public static MySingleton getInstance() { return theInstance; } }
126
Wrapper class example: Double d1 = Double .valueOf(3.14); Double d2 = new Double (3.14);
127
128
Rose Family
Eclipse Plugin
MS Visio
129
130
131
eUML2
132
eUML2 (cont.)
133
Generated from the Appender interface to display its inheritance & ass. relationships ass.
134
135
136