Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

CS 501 Spring 2003 Sequence Diagram by pengxuebo

VIEWS: 0 PAGES: 43

									    CS 501: Software Engineering



                Lecture 18

       Object Oriented Design II




1                            CS 501 Spring 2003
                Administration

    New syllabus
       Quiz 4 on Thursday, April 3 (no lecture)
       Lecture 23 on Wednesday April 16 (evening)
    Second presentation and report next week
       Sign up. Assignment will be posted shortly
    Quiz 3
       Collect after class
    No office hours next week

2                                            CS 501 Spring 2003
          Actor and Use Case Diagram


                   • An actor is a user of a system in a
                     particular role.
    BookBorrower
                      An actor can be human or an external
                      system.

    Borrow book    • A use case is a a task that an actor
                     needs to perform with the help of the
                     system.



3                                                 CS 501 Spring 2003
                  Use Cases and Actors


    • A scenario is an instance of a use case
    • Actor is role, not an individual
          (e.g., librarian can have many roles)
    • Actor must be a "beneficiary" of the use case
          (e.g., not librarian who processes book when borrowed)
    In UML, the system boundary is the set of use cases.




4                                                 CS 501 Spring 2003
      Use Cases for Borrowing Books


                      Borrow copy
                        of book

    BookBorrower
                       Return copy
                         of book


                      Reserve
                       book
           Extend
            loan

5                                   CS 501 Spring 2003
       Relationships Between Use Cases:
                   <<uses>>



                  Extend       <<uses>>
                   loan
                                           Check for
                                          reservation
BookBorrower     Borrow copy   <<uses>>
                   of book




6                                     CS 501 Spring 2003
       Relationships Between Use Cases:
                 <<extends>>




                            <<extends>>    Refuse
                 Borrow copy                loan
BookBorrower       of book




7                                     CS 501 Spring 2003
    Use Cases in the Development Cycle


    • Use cases are a tool in requirements analysis
    • Intuitive -- easy to discuss with clients
    • Use cases are often hard to translate into class models
    • Scenarios are useful to validate design




8                                                 CS 501 Spring 2003
    Modeling Dynamic Aspects of Systems


    Interaction diagrams: set of objects and their relationships
    including messages that may be dispatched among them
    • Sequence diagrams: time ordering of messages
    • Collaboration diagrams: structural organization of
      objects that send and receive messages
    Activity diagram: flow chart showing flow of control from
    activity to activity
    Statechart diagram: models a state machine


9                                                  CS 501 Spring 2003
                      Notation: States



                          Waiting


     A state machine is a behavior that specifies the sequence of
     states an object or an interaction goes through during its
     lifetime in response to events.




10                                                  CS 501 Spring 2003
                   State Diagram


                                             returned()


                       returned()
         not
                                           borrowable
     borrowable
                  borrowed()[last copy]


         guard expression           borrowed()[not last copy]


              State diagram for class Book
11                                               CS 501 Spring 2003
                      A Quiz Question

     A machine tool is controlled by a switch and two buttons:
          power        Turn the power on/off (switch)
          start        Start the machine (button)
          stop         Stop the machine (button)
     There is also a blade guard. To change the blade, the
     power must be off and the blade guard removed.
     To run the machine, press the start button. The power must
     be turned on and the blade guard must be in place.
     The machine runs until the stop button is pressed. While
     the machine is running, the blade guard is locked in place.

12                                                  CS 501 Spring 2003
           A Quiz Question: States

     Power off       Power on           run
     Guard on        Guard on


        safe          ready




      change          danger


      Power off      Power on
      Guard off      Guard off
13                               CS 501 Spring 2003
     A Quiz Question: Transitions

           Transitions
              power on
              power off
              start
              stop
              guard on
              guard off



14                           CS 501 Spring 2003
                A Quiz Question:
              State Transition Table
               power power                      guard   guard
                                start   stop     on      off
                 on   off
      safe     ready                                    change

     change   danger                            safe

     danger            change                   ready

      ready             safe    run                     danger

       run              safe            ready

                   not specified
15                                              CS 501 Spring 2003
                  A Quiz Question:
              State Transition Diagram
                                 power off



                                                start
                      power on
             safe                   ready                  run
                                                stop
     guard          guard   guard            guard
       off          on        off            on
                      power on
         change                     danger
                      power off

16                                                      CS 501 Spring 2003
     Notation for Classes and Objects

         Classes              Objects

       AnyClass          anObject:AnyClass
      attribute1                or
      attribute2
                             :AnyClass
      operation1()
      operation2()              or
                              anObject
           or

       AnyClass         The names of objects are
                        underlined.

17                                CS 501 Spring 2003
             Notation: Active Class


                   EventManager
                  eventlist
                  suspend()
                  flush()

     An active class is a class whose objects own one or
     more processes or threads and therefore can initiate
     control activity.


18                                              CS 501 Spring 2003
                    Notation: Interaction


                               display

     An interaction is a behavior that comprises a set of messages
     exchanged among a set of objects within a particular context to
     accomplish a specific purpose.




19                                                    CS 501 Spring 2003
               Actions on Objects

                      returnCopy(c)
     call
                           okToBorrow()       local


     return              status

     send           notifyReturn(b)        asynchronous
                                              signal
     create            <<create>>
                                           stereotypes
     destroy           <<destroy>>

20                                        CS 501 Spring 2003
              Bouncing Ball Diagrams

      Example: execution of http://www.cs.cornell.edu/

     domain name
     service

     TCP
     connection

     HTTP get



                   Client                       Servers
21                                              CS 501 Spring 2003
     Sequence Diagram: Borrow Copy of a
                    Book

                   libMem:                      theBook:Book
                LibraryMember
BookBorrower                     theCopy:Copy

     borrow(theCopy)
                       okToBorrow

                        borrow
                                       borrow


22                                               CS 501 Spring 2003
        Sequence Diagram: Change in Cornell
                     Program


                           :MEngStudent
     Cornellian

           1 : getName()
              1.1 : name
                  2: new PhDStudent(name)
                                                   :PhDStudent
            3: <<destroy>>


                  sequence numbers added to messages
23                                                     CS 501 Spring 2003
      Sequence Diagram: Painting Mechanism



     :Thread         :Toolkit    :ComponentPeer       target:HelloWorld

run
               run        callbackLoop


                           handleExpose
                                              paint



24                                                    CS 501 Spring 2003
              Other Diagrams in UML


     • Activity diagram is a statechart diagram that shows the
       flow from activity to activity within a system.
     • Component diagram shows the organization and
       dependencies among a set of components.
     • Deployment diagram shows the configuration of
       processing nodes and the components that live on them.




25                                               CS 501 Spring 2003
       Activity Diagram: Process Modeling


                  Release work
                      order

        branch
                            [materials not ready]
                                                      Reschedule

     [materials ready]
                                        guard expression
                 Assign tasks

26                                                  CS 501 Spring 2003
       Activity Diagram: Parallel Activities


            start state

                            Decompress

     fork


             Stream video                Stream audio


     join

            stop state
27                                                 CS 501 Spring 2003
            Implementation Modeling

     Subsystem
     A grouping of elements that specifies what a part of a system
     should do.
     Component (UML definition)
     "A distributable piece of implementation of a system,
     including software code (source, binary, or executable) but
     also including business documents, etc., in a human system."
     A component can be thought of as an implementation of a
     subsystem.


28                                                CS 501 Spring 2003
              Notation: Collaboration



                           Chain of
                        responsibility


     A collaboration defines an interaction, i.e., a society of
     roles and other elements that work together to provide some
     cooperative behavior.




29                                                CS 501 Spring 2003
     Notation: Component & Node

                 orderform.java


     A component is a physical and replaceable
     part of a system that conforms to and provides
     the realization of a set of interfaces.

                   Server


      A node is a physical element that exists at run
      time and represents a computational resource.
30                                            CS 501 Spring 2003
                 Component Diagram

                       executable         hello.java
                       component
     hello.hml
                     HelloWorld.class



                      hello.jpg




31                                      CS 501 Spring 2003
               Components and Classes



     Classes represent logical abstractions. Components represent
     physical things.
     Components may live on nodes.
     Classes have attributes and operations directly. Components
     have operations that are reachable only through interfaces.




32                                                CS 501 Spring 2003
      Components and Classes



                   agent.dll




     AgentAction               PatternSearch

                      Policy

33                              CS 501 Spring 2003
     Components and Classes



            agent.dll
         Realizes
      AgentAction
      PatternSearch
      Policy


                        extended component



34                             CS 501 Spring 2003
                        Interfaces




     simulation.exe                            render.java

                         IRender

           dependency                realization
                        interface


35                                         CS 501 Spring 2003
     Application Programming Interface (API)


     API is an interface that is realized by one or more components.

                              simulation.exe

                                                       IRender




                        IModels      ILighting

36                                                    CS 501 Spring 2003
         Components and Replaceability


     Components allow system to be assembled from binary
     replaceable elements.
     • A component is physical -- bits not concepts
     • A component can be replaced by any other component(s)
       that conforms to the interfaces.
     • A component is part of a system.
     • A component provides the realization of a set of
       interfaces.



37                                                CS 501 Spring 2003
                An Exam Question:
               Object Oriented Design

     A system generates weather maps using data collected from
     unattended weather stations. Each weather station collects
     meteorological data and produces summaries of the data.
     On request, it sends the summary information to an area
     computer. The area computer uses a database of digitized
     maps to generate a set of local weather maps.




38                                                   CS 501 Spring 2003
     Exam Question: Noun Identification


     A system generates weather maps using data collected from
     unattended weather stations. Each weather station collects
     meteorological data and produces summaries of the data.
     On request, it sends the summary information to an area
     computer. The area computer uses a database of digitized
     maps to generate a set of local weather maps.




39                                                   CS 501 Spring 2003
            Exam Question: Candidate Classes


     System               general term
     WeatherMap
     Data                 same as MeteorologicalData
     WeatherStation       is this a general term?
     MeteorologicalData   how does this relate to WeatherStation?
     DataSummary          how does this relate to MeteorologicalData?
     AreaComputer         hardware
     Database             general term
     DigitizedMap

40                                                   CS 501 Spring 2003
     Exam Question: Observations about
          the Candidate Classes

     WeatherMap           is a DigitizedMap
                          is derived from 1...* DataSummary
     WeatherStation       has a set of MeteorologicalData
     MeteorologicalData
     DataSummary          is derived from MeteorologicalData
     DigitizedMap
     Can Meteorological Data be an attribute of WeatherStation?
     Can DataSummary be combined with WeatherMap?


41                                              CS 501 Spring 2003
      Exam Question: Attributes and
              Operations

       WeatherStation        WeatherMap
     location             location
     metereologicalData   date-time
                          geographicData
     collectData()
                          weather
     getSummary()
                          gatherData()
       DigitizedMap       printMap()
     location             Or should
     geographicData       MetereologicalData be a
     printMap()           separate object?
42                                       CS 501 Spring 2003
             Exam Question: Class Diagram

                                                 DigitizedMap




       WeatherStation                              WeatherMap
     location                                   location
     metereologicalData                     1   date-time
                          1...*
     collectData()                              geographicData
                                  summary       weather
     getSummary()
                                                gatherData()
                                                printMap()

43                                                     CS 501 Spring 2003

								
To top