Class Diagrams - PowerPoint PPT Presentation

About This Presentation
Title:

Class Diagrams

Description:

rrr refers to one or more (depending on multiplicity) B objects ... Library example (Facilitate Checkout): Given a borrower's ID Card and the book ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 31
Provided by: johnpaul3
Category:

less

Transcript and Presenter's Notes

Title: Class Diagrams


1
Class Diagrams
  • Software Design and Development

2
Classes in a Class Diagram
  • Class name only Example
  • With Details Example

Bank Account
Class Name
Bank Account double balance deposit() withdraw()
Class Name attributes methods
3
Relationships
  • Inheritance (arrow)
  • example between Secretary and Employee
  • Composition/Aggregation (diamond)
  • example between Car and Wheel
  • Association (line)
  • example between Borrower and Book

4
Inheritance
Employee
public class Secretary extends Employee
Secretary
5
Composition/Aggregation
Car
Wheel
4
w
public class Car Wheel w ...
public Car() w new Wheel4
...
Note in diagram is sometimes left out since
w does not need to be an array
6
Association
Borrower
Book
3
1
currBorr
bk
public class Borrower Book bk
public Borrower() bk new Book3
public class Book Borrower currBorr
7
Notational Details
  • Cardinality
  • Specifies the number of objects that may
    participate in the relationship
  • Roles and Navigability
  • Specifies relationship name and access
  • Aggregation versus Composition
  • Dependencies

8
Cardinality
  • Also known as multiplicity
  • Exact number (mandatory)
  • Range (e.g., 0..5)
  • (many-valued)
  • Specifies the number of objects that may be
    associated with an object of the other class
  • For associations, multiplicity is specified on
    both participants

9
Roles and Navigability
  • Role name placed on the side of a participant
  • Let A and B be associated classes and let rrr be
    the role specified on Bs side
  • rrr is the role of B in the relationship
  • rrr is a member in class A
  • rrr refers to one or more (depending on
    multiplicity) B objects
  • An arrowhead indicates the ability to access B
    participant(s) from A

10
Uni-directional Navigability
PriceChecker getPrice()
FastFood Counter
pc
public class FastFoodCounter PriceChecker
pc public void add( )
double pr pc.getPrice()
public class PriceChecker // no access to
counter
11
Bi-directional Navigability
Borrower
Book
3
1
currBorr
bk
public class Borrower Book bk
public Borrower() bk new Book3
public class Book Borrower currBorr
Note double arrowheads may be omitted
(bi-directionalnavigability assumed)
12
Aggregation versus Composition
  • Part-of relationships
  • Aggregation
  • Part may be independent of the whole but the
    whole requires the part
  • Unfilled diamond
  • Composition (stronger form of aggregation)
  • Part is created and destroyed with the whole
  • Filled diamond
  • Definitions and distinctions between aggregation
    and composition still under debate

13
Mandatory Parts
Car
Wheel
4
wheels
public class Car private Wheel wheels4
// wheel objects are created externally
... public Car(Wheel w1, Wheel w2, ) //
wheels required in constructor // w1, w2,
will be checked for null values
14
Dependencies
  • Some classes use other classes but are not
    related to them in ways previously discussed
  • Not relationships in the sense that participants
    do not become attributes in another class
  • Most common example
  • As local variables in (or arguments to) a method
    of the class

15
Dependency Example
Parser getOrder()
Restaurant processOrders()
uses
public class Restaurant public void
processOrders() Parser p new
Parser() // call getOrder() in this
method
16
Use Cases andObject Interaction
  • Software Design and Development

17
Depicting System Behavior
  • First, identify the use cases
  • Use case typical interaction between a user and
    the system
  • Use Case Diagram
  • Depicts all use cases for a system
  • Interaction Diagram
  • Depicts a single use case as a collection of
    interacting objects

18
ExampleUse Case Diagram
LIBRARY SYSTEM
Facilitate Checkout
Search for Book
Borrower
Librarian
Facilitate Return
19
Use Case Diagram Notation
  • Stick Figures Actors
  • Could be a human user or a subsystem
  • Ellipses - Use Cases
  • Links - between actors and use cases
  • Links between use cases
  • ltltusesgtgt to depict inclusion of a use case
  • ltltextendsgtgt to depict variations of a general
    use case

20
Example ltltusesgtgt
Facilitate Checkout
ltltusesgtgt
Log-in
Librarian
ltltusesgtgt
Facilitate Return
Note UML v.1.3 uses ltltincludesgtgt instead of
ltltusesgtgt
21
Example ltltextendsgtgt
By Author
ltltextendsgtgt
Search for Book query
Borrower
ltltextendsgtgt
By Subject
Note query is called an extension point
22
Describing a Use Case
  • Narrative
  • Library example (Facilitate Checkout) Given a
    borrowers ID Card and the book to be borrowed,
    the librarian enters the borrowers ID number and
    the books catalogue number. If the borrower is
    allowed to check out the book, the system
    displays that the book has been recorded as
    borrowed
  • Or, an Interaction Diagram

23
ExampleInteraction Diagram
2 checkIfAvailable()
Checkout Screen
Book
1 checkIfDelinquent() 3 borrowBook()
4 setBorrower()
Borrower
24
Interaction (Collaboration) Diagram Notation
  • Rectangles Classes/Objects
  • Arrows Messages/Method Calls
  • Labels on Arrows
  • sequence number (whole numbers or X.X.X notation)
  • method name (the message passed)
  • more details, if helpful and necessary
    (iterators, conditions, parameters, types, return
    types)

25
Methods
  • Interaction Diagrams suggest/imply methods for
    classes
  • Has consequences on detailed class diagram
  • The label(s) of an arrow should be a method of
    the class the arrow points to
  • Library System
  • Borrower class should have at least two methods
    (checkIfDelinquent and borrowBook)

26
Including Conditionsand Types
2 avail checkIfAvailable()boolean
Checkout Screen
bBook
1 delinq checkIfDelinquent()boolean 3!delinq
avail borrowBook(Book b)
4 setBorrower( Borrower bk )
rBorrower
27
Interaction Diagramsand Object-Oriented Code
  • Note correspondences between messages passed and
    method calls in actual code
  • Example
  • borrowBook() is defined in Borrower and is called
    from the code in CheckOutScreen
  • setBorrower() is defined in Book and is called
    from borrowBook() method of Borrower
  • Other diagramming details imply if statements and
    loops in code

28
Creating an Object
  • new means a constructor is being called
  • Implies object creation

1 addCustomer(custdetails)
CustomerList
Encoder
2 new
Note this means theaddCustomer method
willcontain code that createsa Customer object
Customer
29
Iteration
  • is an iterator
  • means the method is called repeatedly

1 printSalesSummary()
Store
Manager
2 getTotalSales()
Note Store needs data from all branches to
produce a summary
Branch
30
Summary
  • Provide a Use Case Diagram to depict the use
    cases of a system
  • For each use case, describe and provide an
    Interaction Diagram
  • Depict use case as a collection of interacting
    objects
  • Other diagramming techniques that aid in building
    a dynamic model
  • State diagram describes object state changes
  • Activity diagram describes method behavior
Write a Comment
User Comments (0)
About PowerShow.com