UML Sequence and Class Diagrams

Embed Size (px)

Citation preview

  • 7/27/2019 UML Sequence and Class Diagrams

    1/20

    Page 1 Copyright 1997 by Rational Software Corporation

    Putting the UML to Work

    The ESU University wants to computerize their registrationsystem

    The Registrar sets up the curriculum for a semester

    One course may have multiple course offerings

    Students select 4 primary courses and 2 alternate courses

    Once a student registers for a semester, the billing system isnotified so the student may be billed for the semester

    Students may use the system to add/drop courses for a period oftime after registration

    Professors use the system to receive their course offering rosters

    Users of the registration system are assigned passwords which areused at logon validation

  • 7/27/2019 UML Sequence and Class Diagrams

    2/20

    Page 2 Copyright 1997 by Rational Software Corporation

    Use Case Diagram

    Use case diagrams are created to visualize the relationshipsbetween actors and use cases

    Student

    Registrar

    Professor

    Maintain Schedule

    Maintain Curriculum

    Request Course Roster

    Billing System

  • 7/27/2019 UML Sequence and Class Diagrams

    3/20

    Page 3 Copyright 1997 by Rational Software Corporation

    Use Case Realizations

    The use case diagram presents an outside view of the system

    Interaction diagrams describe how use cases are realized asinteractions among societies of objects

    Two types of interaction diagrams Sequence diagrams

    Collaboration diagrams

  • 7/27/2019 UML Sequence and Class Diagrams

    4/20

    Page 4 Copyright 1997 by Rational Software Corporation

    Sequence Diagram

    A sequence diagram displays object interactions arrangedin a time sequence

    : Student registrationform registratio

    nmanager math 101

    1: fill in info

    2: submit

    3: add course(joe,

    math 01)

    4: are you open?5: are you open?

    6: add (joe)7: add (joe)

    math 101sec

    tion 1

  • 7/27/2019 UML Sequence and Class Diagrams

    5/20

    Page 5 Copyright 1997 by Rational Software Corporation

    Class Diagrams

    A class diagram shows the existence of classes and theirrelationships in the logical view of a system

    UML modeling elements in class diagrams

    Classes and their structure and behavior Association, aggregation, dependency, and inheritance

    relationships

    Multiplicity and navigation indicators

    Role names

  • 7/27/2019 UML Sequence and Class Diagrams

    6/20

    Page 6 Copyright 1997 by Rational Software Corporation

    Classes

    A class is a collection of objects with common structure,common behavior, common relationships and commonsemantics

    Classes are found by examining the objects in sequence andcollaboration diagram

    A class is drawn as a rectangle with three compartments

    Classes should be named using the vocabulary of thedomain

    Naming standards should be created

    e.g., all classes are singular nouns starting with a capital letter

  • 7/27/2019 UML Sequence and Class Diagrams

    7/20

    Page 7 Copyright 1997 by Rational Software Corporation

    Classes

    RegistrationForm

    RegistrationManager

    Course

    Student

    CourseOffering

    Professor

    ScheduleAlgorithm

  • 7/27/2019 UML Sequence and Class Diagrams

    8/20

    Page 8 Copyright 1997 by Rational Software Corporation

    Operations

    The behavior of a class is represented by its operations

    Operations may be found by examining interactiondiagrams

    registrationform

    registrationmanager

    3: add course(joe, math 01)

    RegistrationManager

    addCourse(Student,Course)

  • 7/27/2019 UML Sequence and Class Diagrams

    9/20

    Page 9 Copyright 1997 by Rational Software Corporation

    Attributes

    The structure of a class is represented by its attributes

    Attributes may be found by examining class definitions, theproblem requirements, and by applying domain knowledge

    Each course offering

    has a number, location

    and time

    CourseOffering

    number

    location

    time

  • 7/27/2019 UML Sequence and Class Diagrams

    10/20

    Page 10 Copyright 1997 by Rational Software Corporation

    Classes

    RegistrationForm

    RegistrationManager

    addStudent(Course, StudentInfo)

    Coursename

    numberCredits

    open()

    addStudent(StudentInfo)

    Studentname

    major

    CourseOfferinglocation

    open()

    addStudent(StudentInfo)

    ProfessornametenureStatus

    ScheduleAlgorithm

  • 7/27/2019 UML Sequence and Class Diagrams

    11/20

    Page 11 Copyright 1997 by Rational Software Corporation

    Relationships

    Relationships provide a pathway for communicationbetween objects

    Sequence and/or collaboration diagrams are examined todetermine what links between objects need to exist to

    accomplish the behavior -- if two objects need to talkthere must be a link between them

    Three types of relationships are:

    Association

    Aggregation

    Dependency

  • 7/27/2019 UML Sequence and Class Diagrams

    12/20

    Page 12 Copyright 1997 by Rational Software Corporation

    Relationships

    An association is a bi-directional connection between classes

    An association is shown as a line connecting the related classes

    An aggregation is a stronger form of relationship where therelationship is between a whole and its parts

    An aggregation is shown as a line connecting the related classeswith a diamond next to the class representing the whole

    A dependency relationship is a weaker form of relationshipshowing a relationship between a client and a supplier

    where the client does not have semantic knowledge of thesupplier

    A dependency is shown as a dashed line pointing from theclient to the supplier

  • 7/27/2019 UML Sequence and Class Diagrams

    13/20

    Page 13 Copyright 1997 by Rational Software Corporation

    RegistrationManager

    Math 101:Course

    3: add student(joe)

    RegistrationManager

    Course

    Finding Relationships

    Relationships are discovered by examining interactiondiagrams

    If two objects must talk there must be a pathway forcommunication

  • 7/27/2019 UML Sequence and Class Diagrams

    14/20

    Page 14 Copyright 1997 by Rational Software Corporation

    Relationships

    RegistrationForm

    RegistrationManager

    Course

    Student

    CourseOffering

    Professor

    addStudent(Course, StudentInfo)

    name

    numberCredits

    open()

    addStudent(StudentInfo)name

    major

    location

    open()

    addStudent(StudentInfo)

    nametenureStatus

    ScheduleAlgorithm

  • 7/27/2019 UML Sequence and Class Diagrams

    15/20

    Page 15 Copyright 1997 by Rational Software Corporation

    Multiplicity and Navigation

    Multiplicity defines how many objects participate in arelationships

    Multiplicity is the number of instances of one class related toONE instance of the other class

    For each association and aggregation, there are two multiplicitydecisions to make: one for each end of the relationship

    Although associations and aggregations are bi-directionalby default, it is often desirable to restrict navigation to onedirection

    If navigation is restricted, an arrowhead is added toindicate the direction of the navigation

  • 7/27/2019 UML Sequence and Class Diagrams

    16/20

    Page 16 Copyright 1997 by Rational Software Corporation

    Multiplicity and Navigation

    RegistrationForm

    RegistrationManager

    Course

    Student

    CourseOffering

    Professor

    addStudent(Course, StudentInfo)

    name

    numberCredits

    open()

    addStudent(StudentInfo)major

    location

    open()

    addStudent(StudentInfo)

    tenureStatus

    ScheduleAlgorithm

    10..*

    0..*

    1

    1

    1..*

    4

    3..10

    0..41

  • 7/27/2019 UML Sequence and Class Diagrams

    17/20

    Page 17 Copyright 1997 by Rational Software Corporation

    Inheritance

    Inheritance is a relationships between a superclass and itssubclasses

    There are two ways to find inheritance:

    Generalization

    Specialization

    Common attributes, operations, and/or relationships areshown at the highest applicable level in the hierarchy

  • 7/27/2019 UML Sequence and Class Diagrams

    18/20

    Page 18 Copyright 1997 by Rational Software Corporation

    Inheritance

    RegistrationForm

    RegistrationManager

    Course

    Student

    CourseOffering

    Professor

    addStudent(Course, StudentInfo)

    name

    numberCredits

    open()

    addStudent(StudentInfo)major

    location

    open()

    addStudent(StudentInfo)

    tenureStatus

    ScheduleAlgorithm

    nameRegistrationUser

  • 7/27/2019 UML Sequence and Class Diagrams

    19/20

    Page 19 Copyright 1997 by Rational Software Corporation

    The State of an Object

    A state transition diagram shows

    The life history of a given class

    The events that cause a transition from one state to another

    The actions that result from a state change

    State transition diagrams are created for objects withsignificant dynamic behavior

  • 7/27/2019 UML Sequence and Class Diagrams

    20/20

    Page 20 Copyright 1997 by Rational Software Corporation

    State Transition Diagram

    InitializationOpen

    entry: Register student

    exit: Increment count

    Closed

    Canceled

    do: Initialize course

    do: Finalize course

    do: Notify registered students

    Add Student /Set count = 0

    Add student[ count < 10 ]

    [ count = 10 ]

    Cancel

    Cancel

    Cancel