SlideShare a Scribd company logo
1
Big questions
 What is UML?
 Why should I bother? Do people really use UML?
 What is a UML class diagram?
 What kind of information goes into it?
 How do I create it?
 When should I create it?
2
Design phase
 design: specifying the structure of how a
software system will be written and function,
without actually writing the complete
implementation
 a transition from "what" the system must do, to
"how" the system will do it
 What classes will we need to implement a system
that meets our requirements?
 What fields and methods will each class have?
 How will the classes interact with each other?
3
How do we design classes?
 class identification from project spec / requirements
 nouns are potential classes, objects, fields
 verbs are potential methods or responsibilities of a class
 CRC card exercises
 write down classes' names on index cards
 next to each class, list the following:
 responsibilities: problems to be solved; short verb phrases
 collaborators: other classes that are sent messages by this class
(asymmetric)
 UML diagrams
 class diagrams (today)
 sequence diagrams
 ...
4
Introduction to UML
 UML: pictures of an OO system
 programming languages are not abstract enough for OO design
 UML is an open standard; lots of companies use it
 What is legal UML?
 a descriptive language: rigid formal syntax (like programming)
 a prescriptive language: shaped by usage and convention
 it's okay to omit things from UML diagrams if they aren't
needed by team/supervisor/instructor
5
Uses for UML
 as a sketch: to communicate aspects of system
 forward design: doing UML before coding
 backward design: doing UML after coding as documentation
 often done on whiteboard or paper
 used to get rough selective ideas
 as a blueprint: a complete design to be implemented
 sometimes done with CASE (Computer-Aided Software
Engineering) tools
 as a programming language: with the right tools, code
can be auto-generated and executed from UML
 only good if this is faster than coding in a "real" language
6
UML class diagrams
 What is a UML class diagram?
 What are some things that are not represented in a
UML class diagram?
 details of how the classes interact with each other
 algorithmic details; how a particular behavior is
implemented
 UML class diagram: a picture of the classes in an
OO system, their fields and methods, and
connections between the classes that interact or
inherit from each other
7
Diagram of one class
 class name in top of box
 write <<interface>> on top of interfaces' names
 use italics for an abstract class name
 attributes (optional)
 should include all fields of the object
 operations / methods (optional)
 may omit trivial (get/set) methods
 but don't omit any methods from an interface!
 should not include inherited methods
8
Class attributes
 attributes (fields, instance variables)
 visibility name : type [count] = default_value
 visibility: + public
# protected
- private
~ package (default)
/ derived
 underline static attributes
 derived attribute: not stored, but can
be computed from other attribute values
 attribute example:
- balance : double = 0.00
9
Class operations / methods
 operations / methods
 visibility name (parameters) : return_type
 visibility: + public
# protected
- private
~ package (default)
 underline static methods
 parameter types listed as (name: type)
 omit return_type on constructors and
when return type is void
 method example:
+ distance(p1: Point, p2: Point): double
10
Comments
 represented as a folded note, attached to the
appropriate class/method/etc by a dashed line
11
Relationships btwn. classes
 generalization: an inheritance relationship
 inheritance between classes
 interface implementation
 association: a usage relationship
 dependency
 aggregation
 composition
12
Generalization relationships
 generalization (inheritance) relationships
 hierarchies drawn top-down with arrows
pointing upward to parent
 line/arrow styles differ, based on whether
parent is a(n):
 class:
solid line, black arrow
 abstract class:
solid line, white arrow
 interface:
dashed line, white arrow
 we often don't draw trivial / obvious
generalization relationships, such as
drawing the Object class as a parent
13
Associational relationships
 associational (usage) relationships
1. multiplicity (how many are used)
 *  0, 1, or more
 1  1 exactly
 2..4  between 2 and 4, inclusive
 3..*  3 or more
2. name (what relationship the objects have)
3. navigability (direction)
14
 one-to-one
 each student must carry exactly one ID card
 one-to-many
 one rectangle list can contain many rectangles
Multiplicity of associations
15
Association types
 aggregation: "is part of"
 symbolized by a clear white diamond
 composition: "is entirely made of"
 stronger version of aggregation
 the parts live and die with the whole
 symbolized by a black diamond
 dependency: "uses temporarily"
 symbolized by dotted line
 often is an implementation
detail, not an intrinsic part of
that object's state
1
1
Car
aggregation
Engine
Lottery
Ticket
Random
dependency
Page
Book
composition
*
1
16
Class diagram example 1
17
Class diagram example 2
DVD Movie VHS Movie Video Game
Rental Item
Rental Invoice
1..*
1
Customer
Checkout Screen
0..1
1
Simple
Association
Class
Abstract
Class
Simple
Aggregation
Generalization
Composition
Multiplicity
18
Class diagram example 3
StudentBody
+ main (args : String[])
+ toString() : String
1 100
Student
- firstName : String
- lastName : String
- homeAddress : Address
- schoolAddress : Address
+ toString() : String
- streetAddress : String
- city : String
- state : String
- zipCode : long
Address
19
Tools for creating UML diags.
 Violet (free)
 http://horstmann.com/violet/
 Rational Rose
 http://www.rational.com/
 Visual Paradigm UML Suite (trial)
 http://www.visual-paradigm.com/
 (nearly) direct download link:
http://www.visual-paradigm.com/vp/download.jsp?product=vpuml&edition=ce
(there are many others, but most are commercial)
20
Class design exercise
 Consider this Texas Hold 'em poker game system:
 2 to 8 human or computer players
 Each player has a name and stack of chips
 Computer players have a difficulty setting: easy, medium, hard
 Summary of each hand:
 Dealer collects ante from appropriate players, shuffles the deck,
and deals each player a hand of 2 cards from the deck.
 A betting round occurs, followed by dealing 3 shared cards from
the deck.
 As shared cards are dealt, more betting rounds occur, where each
player can fold, check, or raise.
 At the end of a round, if more than one player is remaining,
players' hands are compared, and the best hand wins the pot of all
chips bet so far.
 What classes are in this system? What are their
responsibilities? Which classes collaborate?
 Draw a class diagram for this system. Include relationships
between classes (generalization and associational).
Ad

More Related Content

Similar to SDA ClassDiagram.ppt (20)

Uml Presentation
Uml PresentationUml Presentation
Uml Presentation
anasz3z3
 
Introduction to UML, class diagrams, sequence diagrams
Introduction to UML, class diagrams, sequence diagramsIntroduction to UML, class diagrams, sequence diagrams
Introduction to UML, class diagrams, sequence diagrams
Dr. Jasmine Beulah Gnanadurai
 
Introduction To Uml
Introduction To UmlIntroduction To Uml
Introduction To Uml
guest514814
 
Uml introduciton
Uml introducitonUml introduciton
Uml introduciton
Dr. C.V. Suresh Babu
 
ooAD
ooADooAD
ooAD
manjulakithsiri
 
Simple uml
Simple umlSimple uml
Simple uml
nilameganathan
 
1. introduction to uml
1. introduction to uml1. introduction to uml
1. introduction to uml
PRABU M
 
Apostila UML
Apostila UMLApostila UML
Apostila UML
landergustavo
 
UML Chart Designing Methods - Lecture.pptx
UML Chart Designing Methods - Lecture.pptxUML Chart Designing Methods - Lecture.pptx
UML Chart Designing Methods - Lecture.pptx
lankanking4
 
SE UML.ppt
SE UML.pptSE UML.ppt
SE UML.ppt
AliZaib71
 
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
leela rani
 
UML- Unified Modeling Language
UML- Unified Modeling LanguageUML- Unified Modeling Language
UML- Unified Modeling Language
Shahzad
 
Uml in software engineering
Uml in software engineeringUml in software engineering
Uml in software engineering
Mubashir Jutt
 
Chapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.pptChapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.ppt
SisayNegash4
 
Chapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.pptChapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.ppt
SisayNegash4
 
Chapterunifiedmo 3 UML Class Diagram.docx
Chapterunifiedmo 3 UML Class Diagram.docxChapterunifiedmo 3 UML Class Diagram.docx
Chapterunifiedmo 3 UML Class Diagram.docx
MohammedNouh7
 
Intro Uml
Intro UmlIntro Uml
Intro Uml
Kris der Rose
 
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejnejeUML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
ssusera6a60c1
 
Uml
UmlUml
Uml
Vishwa Mohan
 
Object Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UMLObject Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UML
Malek Sumaiya
 
Uml Presentation
Uml PresentationUml Presentation
Uml Presentation
anasz3z3
 
Introduction to UML, class diagrams, sequence diagrams
Introduction to UML, class diagrams, sequence diagramsIntroduction to UML, class diagrams, sequence diagrams
Introduction to UML, class diagrams, sequence diagrams
Dr. Jasmine Beulah Gnanadurai
 
Introduction To Uml
Introduction To UmlIntroduction To Uml
Introduction To Uml
guest514814
 
1. introduction to uml
1. introduction to uml1. introduction to uml
1. introduction to uml
PRABU M
 
UML Chart Designing Methods - Lecture.pptx
UML Chart Designing Methods - Lecture.pptxUML Chart Designing Methods - Lecture.pptx
UML Chart Designing Methods - Lecture.pptx
lankanking4
 
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
leela rani
 
UML- Unified Modeling Language
UML- Unified Modeling LanguageUML- Unified Modeling Language
UML- Unified Modeling Language
Shahzad
 
Uml in software engineering
Uml in software engineeringUml in software engineering
Uml in software engineering
Mubashir Jutt
 
Chapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.pptChapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.ppt
SisayNegash4
 
Chapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.pptChapter 2-Unified Modeling Languagee.ppt
Chapter 2-Unified Modeling Languagee.ppt
SisayNegash4
 
Chapterunifiedmo 3 UML Class Diagram.docx
Chapterunifiedmo 3 UML Class Diagram.docxChapterunifiedmo 3 UML Class Diagram.docx
Chapterunifiedmo 3 UML Class Diagram.docx
MohammedNouh7
 
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejnejeUML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
ssusera6a60c1
 
Object Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UMLObject Oriented Modeling and Design with UML
Object Oriented Modeling and Design with UML
Malek Sumaiya
 

Recently uploaded (20)

Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Ad

SDA ClassDiagram.ppt

  • 1. 1 Big questions  What is UML?  Why should I bother? Do people really use UML?  What is a UML class diagram?  What kind of information goes into it?  How do I create it?  When should I create it?
  • 2. 2 Design phase  design: specifying the structure of how a software system will be written and function, without actually writing the complete implementation  a transition from "what" the system must do, to "how" the system will do it  What classes will we need to implement a system that meets our requirements?  What fields and methods will each class have?  How will the classes interact with each other?
  • 3. 3 How do we design classes?  class identification from project spec / requirements  nouns are potential classes, objects, fields  verbs are potential methods or responsibilities of a class  CRC card exercises  write down classes' names on index cards  next to each class, list the following:  responsibilities: problems to be solved; short verb phrases  collaborators: other classes that are sent messages by this class (asymmetric)  UML diagrams  class diagrams (today)  sequence diagrams  ...
  • 4. 4 Introduction to UML  UML: pictures of an OO system  programming languages are not abstract enough for OO design  UML is an open standard; lots of companies use it  What is legal UML?  a descriptive language: rigid formal syntax (like programming)  a prescriptive language: shaped by usage and convention  it's okay to omit things from UML diagrams if they aren't needed by team/supervisor/instructor
  • 5. 5 Uses for UML  as a sketch: to communicate aspects of system  forward design: doing UML before coding  backward design: doing UML after coding as documentation  often done on whiteboard or paper  used to get rough selective ideas  as a blueprint: a complete design to be implemented  sometimes done with CASE (Computer-Aided Software Engineering) tools  as a programming language: with the right tools, code can be auto-generated and executed from UML  only good if this is faster than coding in a "real" language
  • 6. 6 UML class diagrams  What is a UML class diagram?  What are some things that are not represented in a UML class diagram?  details of how the classes interact with each other  algorithmic details; how a particular behavior is implemented  UML class diagram: a picture of the classes in an OO system, their fields and methods, and connections between the classes that interact or inherit from each other
  • 7. 7 Diagram of one class  class name in top of box  write <<interface>> on top of interfaces' names  use italics for an abstract class name  attributes (optional)  should include all fields of the object  operations / methods (optional)  may omit trivial (get/set) methods  but don't omit any methods from an interface!  should not include inherited methods
  • 8. 8 Class attributes  attributes (fields, instance variables)  visibility name : type [count] = default_value  visibility: + public # protected - private ~ package (default) / derived  underline static attributes  derived attribute: not stored, but can be computed from other attribute values  attribute example: - balance : double = 0.00
  • 9. 9 Class operations / methods  operations / methods  visibility name (parameters) : return_type  visibility: + public # protected - private ~ package (default)  underline static methods  parameter types listed as (name: type)  omit return_type on constructors and when return type is void  method example: + distance(p1: Point, p2: Point): double
  • 10. 10 Comments  represented as a folded note, attached to the appropriate class/method/etc by a dashed line
  • 11. 11 Relationships btwn. classes  generalization: an inheritance relationship  inheritance between classes  interface implementation  association: a usage relationship  dependency  aggregation  composition
  • 12. 12 Generalization relationships  generalization (inheritance) relationships  hierarchies drawn top-down with arrows pointing upward to parent  line/arrow styles differ, based on whether parent is a(n):  class: solid line, black arrow  abstract class: solid line, white arrow  interface: dashed line, white arrow  we often don't draw trivial / obvious generalization relationships, such as drawing the Object class as a parent
  • 13. 13 Associational relationships  associational (usage) relationships 1. multiplicity (how many are used)  *  0, 1, or more  1  1 exactly  2..4  between 2 and 4, inclusive  3..*  3 or more 2. name (what relationship the objects have) 3. navigability (direction)
  • 14. 14  one-to-one  each student must carry exactly one ID card  one-to-many  one rectangle list can contain many rectangles Multiplicity of associations
  • 15. 15 Association types  aggregation: "is part of"  symbolized by a clear white diamond  composition: "is entirely made of"  stronger version of aggregation  the parts live and die with the whole  symbolized by a black diamond  dependency: "uses temporarily"  symbolized by dotted line  often is an implementation detail, not an intrinsic part of that object's state 1 1 Car aggregation Engine Lottery Ticket Random dependency Page Book composition * 1
  • 17. 17 Class diagram example 2 DVD Movie VHS Movie Video Game Rental Item Rental Invoice 1..* 1 Customer Checkout Screen 0..1 1 Simple Association Class Abstract Class Simple Aggregation Generalization Composition Multiplicity
  • 18. 18 Class diagram example 3 StudentBody + main (args : String[]) + toString() : String 1 100 Student - firstName : String - lastName : String - homeAddress : Address - schoolAddress : Address + toString() : String - streetAddress : String - city : String - state : String - zipCode : long Address
  • 19. 19 Tools for creating UML diags.  Violet (free)  http://horstmann.com/violet/  Rational Rose  http://www.rational.com/  Visual Paradigm UML Suite (trial)  http://www.visual-paradigm.com/  (nearly) direct download link: http://www.visual-paradigm.com/vp/download.jsp?product=vpuml&edition=ce (there are many others, but most are commercial)
  • 20. 20 Class design exercise  Consider this Texas Hold 'em poker game system:  2 to 8 human or computer players  Each player has a name and stack of chips  Computer players have a difficulty setting: easy, medium, hard  Summary of each hand:  Dealer collects ante from appropriate players, shuffles the deck, and deals each player a hand of 2 cards from the deck.  A betting round occurs, followed by dealing 3 shared cards from the deck.  As shared cards are dealt, more betting rounds occur, where each player can fold, check, or raise.  At the end of a round, if more than one player is remaining, players' hands are compared, and the best hand wins the pot of all chips bet so far.  What classes are in this system? What are their responsibilities? Which classes collaborate?  Draw a class diagram for this system. Include relationships between classes (generalization and associational).