Some Clarifications on the Project
• Doesafeature==astory?
– Itdepends…(onthecomplexityofthefeature)
– E.g.”AsauserIwanttobeabletoloadanimagesoIcanview it.” may be one story, or may need to be broken into multiple…
“As a user I want to be able to load an image from the local file system so I can view my local files.”
”As a user I want to be able to load an image from my OneDrive account so I can view my shared files.”
• Do you have to split all stories into tasks at this stage? (Sprint 0)
– No!Theproductbacklogsimplycontainsstoriesandapriority for each story
CIS 3760
Software Engineering
1
How Many Stories?
• Product/SprintBacklog
– Itreallydependsonthesizeofthestoriesyoumake,but historically in this class, for the same project, groups typically complete 3-4 user stories per sprint (for 2 week sprint)
Each story broken down into 4+ tasks (e.g. 1-2 UI changes, 1-2 data/database changes, testing)
– Soacrosstheproject,teamsoftenimplement10+storiesfrom their product backlog. Note, it may not begin this large, but you’ll get better at breaking down stories as per prior slide as you go.
CIS 3760
Software Engineering
2
CIS 3760: Software Engineering OO Design Basics and Unified
Modeling Language (UML)
Instructor: Prof. Stacey Scott
School of Computer Science
University of Guelph https://www.uoguelph.ca/computing/people/stacey-scott stacey.scott@uoguelph.ca
© 2017-20 Stacey D. Scott
Overview
• Review of OO design concepts, modeling, and UML notation
• Review of common UML diagrams:
– Usecasediagrams,Classdiagrams,Sequencediagrams,State Machine Diagrams
• Detailed notes in slide deck for your at-home review
CIS 3760
Software Engineering
SlidesadaptedfromBruegge&Dutoit,Pearsononlineresources 4
Object-Oriented Design Basics: Classes, Objects
UML Class diagram of Class: Cat
CIS 3760
Software Engineering from Shvets, “Dive into Design Patterns”
5
Object-Oriented Design Basics: Inheritance
UML Class diagram with 3 Classes: Animal, Cat, Dog
CIS 3760
Software Engineering
from Shvets, “Dive into Design Patterns”
6
4 Main Pillars of OOP
CIS 3760
Software Engineering from Shvets, “Dive into Design Patterns”
7
Polymorphism example in pseudocode
1 bag = [new Cat(), new Dog()]; 2
3 foreach (Animal a : bag)
4 a.makeSound()
5
6 // Meow!
7 // Woof!
CIS 3760
Software Engineering
8
We use models (e.g. UML) to abstract and describe the software system
• Functionalmodel:Whatarethefunctionsofthe system?
• Object model: What is the structure of the system? • Dynamicmodel:Howdoesthesystemreactto
external events?
• SystemModel:Objectmodel+functionalmodel+ dynamic model
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 9
Transformations b/w Model and Code Space
Model space
Source code space
Model
trans- formation
Reverse engineering
System Model (in UML)
Another System Model
Another Program
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources10
Forward engineering
Program (in Java)
Refactoring
Next-Week’s Deliverable:
Analysis and Modeling of the Existing Code
Model space
Source code space
Model
trans- formation
Reverse engineering
System Model (in UML)
Another System Model
Another Program
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 11
Forward engineering
Program (in Java)
Refactoring
Coding Sprints: (Re-)Implementation
Model space
Source code space
Model
trans- formation
Reverse engineering
System Model (in UML)
Another System Model
Another Program
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 12
Forward engineering
Program (in Java)
Refactoring
What is UML?
• UML (Unified Modeling Language)
– Nonproprietary standard for modeling
software systems
– Proposedandmaintainedby
OMG (Object Management Group)
– Convergenceofnotationsusedinearlierobject-orientedmethods (e.g., Object Modeling Technique, Booch modeling, Object-Oriented Software Engineering)
• Current Version: UML 2.5.1 (2017; OMG UML portal http://www.uml.org)
• Commercial tools: Enterprise Architect (Sparx Systems), Rational Software Architect (IBM), Visual Studio/Visio (Microsoft), SmartDraw, Astah (Change Vision), …
• Open Source tools: PlantUML, ArgoUML, StarUML, Umbrello, …
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 13
If UML is new to you, or you don’t remember it well… recommended web resources for independent review
• https://www.uml-diagrams.org
– Examples of many different UML diagrams
– Our Class Diagrams are typically “conceptual” class diagrams, and relate best to their “Domain Model Diagrams”
• Lynda.com (LinkedIn Learning):
– E.g. Understanding UML: https://www.linkedin.com/learning/c-plus- plus-design-patterns-creational/understanding-uml?u=56996833 (course also has short modules on abstract vs. concrete classes and inheritance vs. composition, which are important concepts to know for using Software Design Patterns)
– E.g. Modeling with UML: https://www.linkedin.com/learning/ software- design-modeling-with-uml/modeling-languages?u=56996833
CIS 3760
Software Engineering
14
Common UML Diagrams
• Use case diagrams
– Describethefunctionalbehaviorof the system as seen by the user
• Class diagrams
– Describethestaticstructureofthe system: Objects, attributes, associations
• Interaction (Sequence) diagrams
– Describethedynamicbehavior between objects of the system
• State machine diagrams
https://d2slcw3kip6qmk.cloudfront.net/marketing/pages/chart/ what-is-a-use-case-diagram-in-UML/UML_use_case_example- 800×707.PNG
– Describethedynamicbehaviorofan individual object
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 15
Common UML Diagrams
• Use case diagrams
– Describe the functional behavior of the system as seen by the user
• Class diagrams
– Describethestaticstructureofthe system: Objects, attributes, associations
• Interaction (Sequence) diagrams
– Describethedynamicbehavior between objects of the system
• State machine diagrams
https://online.visual-paradigm.com/repository/images/e952006a- 41a9-4866-83dd-8dad5219dc15.png
– Describethedynamicbehaviorofan individual object
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 16
Common UML Diagrams
• Use case diagrams
– Describe the functional behavior of the system as seen by the user
• Class diagrams
– Describethestaticstructureofthe system: Objects, attributes, associations
• Interaction (Sequence) diagrams
– Describethedynamicbehavior between objects of the system
• State machine diagrams
https://cdn.visual-paradigm.com/tutorials/ sequenceanimation_screenshots/01-simple-sequence-diagram.png
– Describethedynamicbehaviorofan individual object
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 17
Common UML Diagrams
• Use case diagrams
– Describe the functional behavior of the system as seen by the user
State machine diagram for a Seminar (or Course)
• Class diagrams
– Describethestaticstructureofthe system: Objects, attributes, associations
• Interaction (Sequence) diagrams
– Describethedynamicbehavior between objects of the system
• State machine diagrams
http://agilemodeling.com/style/stateChartDiagram.htm
– Describethedynamicbehaviorofan individual object
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 18
How these common UML diagrams fit into the broader set of UML diagrams
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 19
Different UML diagrams help model different aspects of the system…
• Functionalmodel:Whatarethefunctionsofthe system?
– UMLusecasediagrams
• Object model: What is the structure of the system?
– UMLclassdiagrams(diagramsaresuccessivelyrefined…) • Dynamicmodel:Howdoesthesystemreactto
external events?
– UMLinteraction(sequence)diagrams – UMLstatemachinediagrams
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 20
For this course…
• We will focus on use case, class, and sequence diagrams only
CIS 3760
Software Engineering
21
UML Use Case Diagrams
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 22
Use case diagram review
System/ Subsystem Boundary
System/Subsystem Name
Use case diagrams represent the functionality of the system from user’s point of view
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 23
Use Case
Actor
Actor
CIS 3760
Software Engineering
24
Example: Use Case Diagram
Actor
Example II: Use Case Diagram SimpleWatch Use Case Diagram (high-level)
CIS 3760
Software Engineering
25
UML Class Diagrams
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 26
Class diagram review
2
2
1 Time
PushButton
state
1
Battery push() blinkIdx Load
release()
blinkSeconds()
blinkMinutes()
blinkHours()
stopBlinking()
refresh()
LCDDisplay
Now
SimpleWatch 1111
Class diagrams represent the structure of the system
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 27
Level of Detail of Class Specification
• The class name is the only mandatory information
• When all attributes / operations are also detailed, this is called a
“fully specified” class
A Fully Specified Class
A Class
TarifSchedule
Zone2price: Table
TarifSchedule
getZones(): Enumeration
getPrice(Zone): Price
CIS 3760
Software Engineering
28
(Even more) Fully Specified Class
TarifSchedule
-Zone2price: Table
+getZones(): Enumeration
+getPrice(Zone): Price
Aside: Terminology
• UML: Attribute & Operation • C++: Variable & Function • Java: Member & Method
CIS 3760
Software Engineering
29
Which sentences are true?
a) CheckingAccount implements BankAccount
b) CheckingAccount and SavingAccount are BankAccount c) CheckingAccount and SavingAccount are associated
d) BankAccount is associated with CheckingAccount
e) SavingAccount can processCheck
f) CheckingAccount has a balance
CIS 3760
Software Engineering
30
Some Review & Discussion: Class Diagrams
Questions:
1
2
3
• What type of notation is “1”? What does “0…1” mean?
• What does the number at “2” mean?
• What assumptions did the system designer make? What
other options are there?
• What does the arrow on the association line mean?
• What type of association does “3” indicate?
CIS 3760 •
Software Engineering
What is another design option for this Person-Student,
Person-Professor relationship?
31
Class Diagrams: Right or Wrong?
A B
CIS 3760
Software Engineering
32
Ex I: “Conceptual” Class Diagram for an Order System
CIS 3760
Software Engineering
From Fowler & Scott (1997). “UML Distilled”. Addison-Wesley. 33
Ex. II: Same System Modeled as an “Implementation” Class Diagram
Notice the association between Order and Customer now specifies the “navigability” between classes.
Means that Order “knows” about Customer, but Customer does not “know” about Order. In the implementation, this means that Order contains a Customer object, but Customer doesn’t contain an Order object.
Navigability is an implementation detail and is not needed in conceptual Class Diagrams (our main focus in this course)
CIS 3760
Software Engineering
From Fowler & Scott (1997). “UML Distilled”. Addison-Wes3le4y.
Conceptual UML Class Diagram Implementation UML Class Diagram
CIS 3760
Software Engineering
From Fowler & Scott (1997). “UML Distilled”. Addison-Wes3le5y.
Packages
• Packages help you to organize UML models to increase their readability
• We can use the UML package mechanism to organize classes into subsystems
Bank
Customer
• Any complex system can be decomposed into subsystems, where each subsystem is modeled as a package.
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 36
Account
Breakout Room UML Class Interpretation Activity
• See Handout “6-UML Class Diagrams Activity-handout”
• As a group answer the 3 class diagram questions (pp. 5- 7)
CIS 3760
Software Engineering
37
UML Sequence Diagrams
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 38
UML Sequence diagram review – setting the time on the SimpleWatch
:WatchUser
pressButton1()
blinkHours()
Lifeline Activation
pressButton1()
pressButton2()
blinkMinutes()
incrementMinutes()
:SimpleWatch
:LCDDisplay
:Time
pressButton1and2()
commitNewTime()
Message
stopBlinking()
Sequence diagrams represent the behavior of a system
as messages (“interactions”) between different objects
CIS 3760
Slides adapted from Bruegge & Dutoit, Pearson online resources 39
Software Engineering
refresh()
Object
Sequence Diagrams
Focus on Control flow
Passenger
Participating Object
TicketMachine
selectZone()
Message = Operation on
insertCoins()
pickupChange()
zone2price
selectZone()
insertCoins()
pickupChange()
pickUpTicket()
pickUpTicket()
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 40
TicketMachine
Alternatives in control flow
CIS 3760
Software Engineering
https://cdn.visual-paradigm.com/tutorials/ sequenceanimation_screenshots/01-simple-sequence-diagram.png
41
CIS 3760
Software Engineering
42
•
Based only on information you can derive from the Course Registration Sequence Diagram (handout/prior slide), draw a partial UML Class Diagram for the StudentPortal system.
Activity: Understanding Sequence Diagrams
– Include ONLY the CourseSection and Student classes (do NOT include the StudentPortalUI, Course, or Registration classes).
– Fully specify any attributes and operations belonging to each class that would be needed to support the logic and functionality detailed in the Sequence Diagram.
– Detail all associations and their multiplicity between participating classes (based on the diagram AND your domain knowledge of students, courses, and course sections)
• For Zoom:
https://docs.google.com/presentation/d/1H6GYbAnLrzzgeq52
tpDXBJge3FUWF2bfq7ob01SLJ34/copy
CIS 3760
Software Engineering
43
Heuristics for Sequence Diagrams (e.g. good
system design dynamics)
• Layout:
– 1st column: Should be the actor of the use case
– 2nd column: Should be a boundary object
– 3rd column: Should be the control object that manages the
rest of the use case
• Creation of objects:
– Create control objects at beginning of event flow – The control objects create the boundary objects
• Access of objects:
– Entity objects are objects that contain system data
– Entity objects can be accessed by control and boundary
objects
– Entity objects should not access boundary or control object
CIS 3760
Software Engineering
44
Sequence Diagram for the ReportEmergency Use Case
CIS 3760
Software Engineering
45
Better: Sequence Diagram for the ReportEmergency Use Case
Boundary Control Actor Object Object
CIS 3760
Software Engineering
46
Better: Sequence Diagram for the ReportEmergency Use Case
Actor
Boundary Object
Control Object
CIS 3760
Software Engineering
47
Entity Objects?
…
Sequence Diagram for the ReportEmergency Use Case (cont’d)
CIS 3760
Software Engineering
48
UML Basic Notation Summary
• UML provides a wide variety of notations for modeling many aspects of software systems
• We’ve concentrated on a few notations:
– Functional model: Use case diagram
– Objectmodel:Classdiagram
– Dynamicmodel:interaction(sequence)diagram
Another Dynamic model: state machine diagrams
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 49
UML Modeling Exercise – Translating Problem Domain Description to a Conceptual Design Model
How should we even approach this problem?
What concrete strategies could we use?
Conducting a textual analysis of the problem domain to identify modeling components:
• Identify “entity” objects – the persistent information tracked by the system (Application domain objects, also called “Business objects”)
– Later refinement of the model, or later in the design/development process you will identify “boundary” and “control” objects (previously discussed)
• To identify objects from a problem description, use case description, scenario, etc., you can use the Abbot Technique:
– Textual analysis (noun-verb analysis)
Nouns are candidates for objects/classes Verbs are candidates for operations
CIS 3760
Software Engineering
50
Mapping grammatical constructs to model components (Abbot’s Technique)
Example
Grammatical construct
UML model component
“Monopoly”
Proper noun
object
Toy
Improper noun
class
Buy, recommend
Doing verb
operation
Is a
being verb
inheritance
has an
having verb
aggregation
must be
modal verb
constraint
dangerous
adjective
attribute
enter
transitive verb
operation
depends on
intransitive verb
Constraint, class, association
CIS 3760
Software Engineering
51
UML Modeling Exercise – Translating Problem Domain Description to a Conceptual Design Model
Exercise instructions
• Identify the “entity” objects (Classes) (circle in text)
• Identify the associations (draw a box around) – Association
– Aggregations – Inheritance
• Identify the associations / attributes (underline in text)
CIS 3760
Software Engineering
52
A hockey league is made up of at least four hockey teams. Each hockey team is composed of six to twelve players, and one player captains the team. Each player only plays for one team. A team has a name and a record. Players have a number and a position. Hockey teams play games against each other. Each game has a score and a location. Teams are sometimes led by a coach. A coach has a level of accreditation and a number of years of experience, and can coach multiple teams. Coaches and players are people, and people have names and addresses.
53
CIS 3760
Software Engineering
© S. Easterbrook, CSC340, University of Toronto
54
Midterm Information and Prep
• Midterm held during regular Lecture time on Thurs, Mar 4
• Midterm will be given in CourseLink Quiz – Norespondus
• Format:
– Closedquestions(MC,TF,matching,etc.) – Writtenanswers
• More materials and prep next week
CIS 3760
Software Engineering
55
Additional References
• Martin Fowler
– UMLDistilled:ABriefGuidetotheStandardObjectModeling Language, 3rd ed., Addison-Wesley, 2003
• Grady Booch,James Rumbaugh,Ivar Jacobson
– TheUnifiedModelingLanguageUserGuide,AddisonWesley,2nd edition, 2005
• Open Source UML tools
– http://java-source.net/open-source/uml-modeling
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 56
Review Materials to Brush up on if you don’t remember UML (or if you haven’t taken it before)
Abstraction
• Abstraction allows us to ignore non-essential details • Two definitions for abstraction:
• Abstraction is a thought process where ideas are distanced from objects
• Abstraction as activity
• Abstraction is the resulting idea of a thought process where an
idea has been distanced from an object
• Abstraction as entity
• Ideas can be expressed by models
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 58
Brief overview of UML Diagramming Concepts
• Excerpt from Lynda.com tutorial:
• C++ Design Patterns: Creational Patterns
– (UnderstandingUMLsegment)
– https://www.linkedin.com/learning/c-plus-plus-design-patterns- creational/understanding-uml?u=56996833
– This online course also has short modules on abstract vs. concrete classes and inheritance vs. composition, which are important concepts to know for using Software Design Patterns
CIS 3760
Software Engineering
59
More online resources on UML High-level overview by SmartDraw
• SmartDraw System:
– https://www.smartdraw.com/uml-diagram
• Video overview of UML diagramming in SmartDraw: https://youtu.be/tqoS1hPQmXQ)
CIS 3760
Software Engineering
60
UML Core Conventions
•
All UML Diagrams denote graphs of nodes and edges – Nodesareentitiesanddrawnasrectanglesorovals – Rectanglesdenoteclassesorinstances
– Ovalsdenotefunctions
•
Names of Classes are not underlined • SimpleWatch
• Firefighter
•
Names of Instances are underlined • myWatch:SimpleWatch
• Joe:Firefighter
•
An edge between two nodes denotes a relationship between the corresponding entities
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 61
Use Case Diagrams
62
Use Case
PurchaseTicket
• Use cases can be described textually, with a focus on the event flow between actor and system
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 63
• A use case represents some functionality provided by the system
Use case diagram basics
Class (not an instance)
Classifier
Use case Function
Actor
Use case diagrams represent the functionality of the system from user’s point of view
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 64
System boundary
UML Use Case Diagrams
Passenger
• Used during requirements elicitation and analysis to represent external behavior (“visible from the outside of the system”)
PurchaseTicket
• The set of all use cases that completely describes the functionality of the system
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 65
• Actors & use cases
• Use case model
Actors
Passenger
• An actor has a unique name and an
Name
– Passenger: A person in the train
– GPS satellite: An external system that provides
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 66
• An actor models an external entity which interacts (communicates) with the system:
– User
– External system (Another system)
– Physicalenvironment(e.g.Weather)
optional description • Examples:
Optional Description
the system with GPS coordinates.
Use Cases often have an Accompanying Textual Description, e.g.
1. Name: Purchase ticket 2. Participating actor:
5. Flow of events:
Passenger
1. Passenger selects the number of zones to be traveled
3. Entry condition:
2. Ticket Distributor displays the amount due
• Passenger stands in front of ticket distributor
3. Passenger inserts money, at least the amount due
• Passenger has sufficient money to purchase ticket
4. Ticket Distributor returns change
4. Exit condition:
• Passenger has ticket
5. Ticket Distributor issues ticket 6. Special requirements: None.
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 67
Passenger
• It has been 15 hours, but the passenger has not finished the purchase process …
PurchaseTicket
• Purchasing a single ticket and purchasing a multi-trip pass involves the same type of money collection process. Do we need to write two different use cases?
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 68
But …
• What if the passenger cancels the ticket purchase before completing the purchase?
Uses Cases can be related
• Extends Relationship
– To represent seldom invoked use cases or exceptional functionality
• Includes Relationship
– Torepresentfunctionalbehaviorcommontomorethanoneuse case.
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 69
The <
<
OutOfOrder
<
Passenger
• The exceptional event flows are factored out of the main event flow for clarity
PurchaseTicket
• The direction of an <
<
Cancel
CIS 3760
Software Engineering
NoChange
• models exceptional or seldom invoked cases
<
TimeOut
Slides adapted from Bruegge & Dutoit, Pearson online resources 70
The <
Passenger
• <
PurchaseMultiCard
PurchaseSingleTicket
• The direction of a <
<
<
<
CollectMoney
NoChange
Cancel
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 71
<
• Represents common functionality needed in more than one use case
The <
• Specializes the parent use case
PayWithCash
PayWithCreditCard
CollectMoney
• The parent use case represents the general steps
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 72
by adding more details
• The child use case inserts additional steps or refines steps
Class Diagrams
73
Class diagram basics
Multiplicity
https://cdn.instructables.com/F26/MSCX/ J8F5SWIB/F26MSCXJ8F5SWIB.LARGE.jpg
3XVK%XWWRQ
‘LVSOD\ %DWWHU\ 7LPH
Association
6LPSOH:DWFK
Class diagrams represent the structure of the system
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 74
Class
Class diagram basics (cont’d)
Class diagrams represent the structure of the system
Association Multiplicity
Class
2
2
1 Time
PushButton
state
1
Battery push() blinkIdx Load
release()
blinkSeconds()
blinkMinutes()
blinkHours()
stopBlinking()
refresh()
Attribute
Operations
Slides adapted from Bruegge & Dutoit, Pearson online resources 75
CIS 3760
Software Engineering
LCDDisplay
SimpleWatch 1111
Now
Class Diagrams
• Used during requirements analysis to model application domain concepts
• Used during design activities to model subsystems and to specify the detailed behavior and attributes of classes
• Can be modeled at different levels of detail, depending on purpose
TarifSchedule
Trip
zone:Zone
Table zone2price
Enumeration getZones()
Price getPrice(Zone)
*
*
Price: Price
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 76
• •
A class represents a concept
A class encapsulates state (attributes) and behavior (operations)
Classes
Type
TarifSchedule
zone2price
getZones()
getPrice()
Signature
Name Attributes
Zone2price: Table
getZones(): Enumeration
getPrice(Zone): Price
Operations
Each attribute has a type
Each operation has a signature (operation name, arguments, and return type)
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources
TarifSchedule
Associations
TarifSchedule
TripLeg
getZones(): Enumeration
getPrice(Zone): Price
*
*
Price Zone
Associations denote relationships between classes
The multiplicity of an association end denotes how many objects the instance of a class can legitimately reference:
– No multiplicity implies 1
– 0…1 – zero or one
– 0…n–0ton(n>=1) – 0…*or*-0tomany – 1…*-1tomany
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources
Multiplicity
Aggregation Association
• An aggregation is a special case of association denoting a “consists-of” hierarchy
Exhaust system
• The aggregate is the parent class, the components are the child classes
1
0..2
A solid diamond denotes composition: A strong form of aggregation where the life time of the component instances is controlled by the aggregate. That is, one part “owns” the other, not just “uses” (as in aggregration).
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 79
TicketMachine
3
Muffler diameter
Tailpipe diameter
ZoneButton
Inheritance Association
CancelButton
ZoneButton
Button
• Inheritance is another special case of an association denoting a “kind-of” hierarchy
• Inheritance simplifies the analysis model by introducing a taxonomy
• The child classes inherit the attributes and operations of the parent class.
CIS 3760
Software Engineering
80
Slides adapted from Bruegge & Dutoit, Pearson online resources
Defining Visibility in Class Diagrams Specifies who can “see” or access the attribute or
operation in the class (i.e. its scope)
https://miro.medium.com/max/1300/1*cjxQc8YklOZGQNeCQVmGkg.png
CIS 3760
Software Engineering
81
Model-Driven Software Development
1. Build a platform-independent model of an applications functionality and behavior
a) Describe model in modeling notation (UML) b) Convert model into platform-specific model
2. (Automatically) generate executable from platform- specific model
Advantages:
– Code is (“mostly”) generated from model
– Portability and interoperability
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 82
Model-driven Software Development
Reality: A stock exchange lists many companies. Each company is identified by a ticker symbol.
Analysis results in analysis object model (UML Class Diagram):
StockExchange
**
Company tickerSymbol
Implementation results in source code (Java):
are mapped to
Lists
public class StockExchange {
public Vector m_Company = new Vector();
};
public class Company {
};
public int m_tickerSymbol;
public Vector m_StockExchange = new Vector();
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 83
Associations
Attributes!
Sequence Diagrams
84
UML Sequence diagram basics
Actor Message Object Lifeline
:WatchUser
:SimpleWatch :LCDDisplay :Time
pressButton1()
blinkHours()
pressButton1()
pressButton2()
blinkMinutes()
incrementMinutes()
pressButton1and2()
commitNewTime()
Activation
stopBlinking()
Sequence diagrams represent the behavior of a system
as messages (“interactions”) between different objects
CIS 3760
Slides adapted from Bruegge & Dutoit, Pearson online resources 85
Software Engineering
refresh()
Sequence Diagrams
Passenger
– to find additional “participating” objects
TicketMachine
selectZone()
– To refine use case descriptions
insertCoins()
• Instances are represented by rectangles, Actors by stick figures
pickupChange()
• Lifelines are represented by dashed lines
pickUpTicket()
• Activations are represented by narrow rectangles.
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 86
• Used during analysis
• Used during system design
– to refine subsystem interfaces
• Messages are represented by arrows
•
The source of an arrow indicates the activation which sent the message
•
Horizontal dashed arrows indicate data flow, for example return results from a message
Sequence Diagrams can also model Data Flow
Passenger
ZoneButton TarifSchedule Display
selectZone()
lookupPrice(selection)
Dataflow
displayPrice(price)
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 87
price
…continued on next slide…
Sequence Diagrams: Iteration & Condition
Passenger
ChangeProcessor CoinIdentifier
Display
CoinDrop
• •
Iteration is denoted by a * preceding the message name
Condition is denoted by boolean expression in [ ] before the message
*
insertChange(coin)
Iteration Condition
price
displayPrice(owedAmount)
name
…continued from previous slide…
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 88
lookupCoin(coin)
[owedAmount<0] returnChange(-owedAmount)
...continued on next slide...
Creation and destruction
Passenger
ChangeProcessor
Creation of Ticket
<
…continued from previous slide…
<
print()
<
Destruction of Ticket
Ticket
• Creation is denoted by a message arrow to the object and the label
• Destruction is denoted by an X mark at the end of the destruction activation, typically also by the label <
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 89
Sequence Diagram Properties
• UML sequence diagram represent behavior in terms of interactions
• Useful to identify missing objects
• Time consuming to build, but worth the investment
• Complement the class diagrams (which represent structure).
CIS 3760
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources 90
How do we detect Operations?
• We look for objects that are interacting and extract their “protocol”
• We look for objects that have interesting behavior on their own
• Good starting point: Flow of events in a use case description
• From the flow of events we proceed to the sequence diagram to find the participating objects.
CIS 3760
Software Engineering
91
What is an Event?
• Something that happens at a point in time
• An event sends information from one object to another
• Events can have associations with each other: – Causallyrelated:
An event happens always before another event
An event happens always after another event – Causallyunrelated:
Events that happen concurrently
• Events can also be grouped in event classes with a
hierarchical structure => Event taxonomy.
CIS 3760
Software Engineering
92
The term ‘Event’ is often used in two ways
• Instance of an event class:
– “Slide14shownonFridayNovember27at9:23”
– Event class “Lecture Given”, Subclass “Slide Shown”
• Attribute of an event class
– SlideUpdate(8:55AM,11/27/2009)
– Train_Leaves(4:45pm, Manhattan)
– Mousebuttondown(button#,tablet-location).
CIS 3760
Software Engineering
93
Finding Participating Objects for Sequence Diagram
• Heuristic for finding participating objects:
– Aeventalwayshasasenderandareceiver
– Findthesenderandreceiverforeachevent=>Thesearethe objects participating in the use case.
CIS 3760
Software Engineering
94
An Example
• Flow of events in “Get SeatPosition” use case :
1. Establish connection between smart card and onboard computer
2. Establish connection between onboard computer and sensor for seat
3. Get current seat position and store on smart card • Where are the objects?
CIS 3760
Software Engineering
95
time
Sequence Diagram for “Get SeatPosition”
1. Establish connection between smart card and onboard computer
Establish Connection
2. Establish connection between onboard computer and seat (actually seat sensor)
Accept Connection
3. Get current seat position and store
Accept Connection Get SeatPosition
on smart card.
“500,575,300”
Smart Card Onboard Computer Seat Establish Connection
CIS 3760
Software Engineering
96
What else can we get out of Sequence Diagrams?
• Sequence diagrams are derived from use cases
• The structure of the sequence diagram helps us to determine how decentralized the system is
• We distinguish two structures for sequence diagrams – Fork Diagrams and Stair Diagrams (Ivar Jacobsen)
CIS 3760
Software Engineering
97
Fork Diagram
• The dynamic behavior is placed in a single object, usually a control object
Control Object
– Itknowsalltheotherobjectsandoftenusesthemfordirect questions and commands
CIS 3760
Software Engineering
98
Stair Diagram
• The dynamic behavior is distributed. Each object delegates responsibility to other objects
– Eachobjectknowsonlyafewoftheotherobjectsandknows which objects can help with a specific behavior
CIS 3760
Software Engineering
99
Fork or Stair?
• Object-oriented supporters claim that the stair structure is better
• Modeling Advice:
– Choose the fork (a centralized control structure) if
The operations can, and may, change order
New operations are expected to be added as a result of new requirements.
– Choosethestair(adecentralizedcontrolstructure)if
The operations have a strong connection
The operations will always be performed in the same order
Care must be taken with this model in a thread-based
system if multiple objects may change the state of the
same data object
CIS 3760
Software Engineering
100
Additional Materials (optional)
101
Basics of State Machine Diagram
CIS 3760
Software Engineering
102
Slides adapted from Bruegge & Dutoit, Pearson online resources
State Machine Diagram (basics)
EXWWRQ3UHVVHG
%OLQN +RXUV
EXWWRQ3UHVVHG
,QFUHPHQW
+RXUV
EXWWRQ3UHVVHG
%OLQN EXWWRQ3UHVVHG ,QFUHPHQW
6WRS
%OLQNLQJ
%OLQN
6HFRQGV
,QFUHPHQW
6HFRQGV
dynamicCIS 3760
EXWWRQ
3UHVVHG
EXWWRQ3UHVVHG
EXWWRQ3UHVVHG
0LQXWHV
0LQXWHV
Represent behavior of a single object with interesting
behavior.
103
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources
EXWWRQ3UHVVHG
EXWWRQ3UHVVHG
State
0LQXWHV
0LQXWHV
State Machine Diagram (basics)
Event
Initial state
EXWWRQ3UHVVHG
%OLQN +RXUV
EXWWRQ3UHVVHG
,QFUHPHQW
+RXUV
Transition
EXWWRQ3UHVVHG
EXWWRQ3UHVVHG
%OLQN EXWWRQ3UHVVHG ,QFUHPHQW
EXWWRQ
EXWWRQ3UHVVHG
EXWWRQ3UHVVHG
3UHVVHG
6WRS %OLQN %OLQNLQJ 6HFRQGV
,QFUHPHQW
6HFRQGV
Final state
Represent behavior of a single object with interesting
dynamicCIS 3760
behavior.
104
Software Engineering
Slides adapted from Bruegge & Dutoit, Pearson online resources
EXWWRQ3UHVVHG