The object-oriented approach to requirements

Document Sample
The object-oriented approach to requirements Powered By Docstoc
					      The object-oriented approach to requirements

             The Unified Modeling Language and the Object Management Group
                               Object-Oriented Requirements
                                     The Class Diagram
              The System Activities:An Object-Oriented Use Case/Scenario View
                 Object Interactions: Collaboration and Sequence Diagrams
              Object Behavior: States, State transition, and Statechart Diagrams

Management information system              7_ 1                                    Huang Hong
       UML and OMG
       Object-Oriented Requirements
            System Activities
            Class diagram
            Use case and use case diagram
                Actor,Scenario,use case
                <Includes> relation between use cases
                comparison between use case diagram and DFD
                use case diagram development*
            Object Interactions
                Message
                Sequence diagram
                Symbols used in sequence diagram
                sequence diagram comprehension*
                sequence diagram development*
                Collaboration diagram
                Comparison of sequence diagram and collaboration diagram
            Object Behavior:
                States, State transition, and Statechart Diagram notation
                Concurrent behavior
                Statechart Diagram comprehension and development
Management information system              7_ 2                              Huang Hong
           Northwoods kayaks: identifying the methods
                       within the objects
       From this Flash movie, what can we learn about the activities a
        analyst must do during a system analysis using OO approach.

       Can you tell some types of the models used in OO analysis.

       Words:get the hang of (of sth.)熟悉某物的用法, 掌握做某事的窍
        门, 理解某事, 摸清概况, 鉴赏

Management information system       7_ 3                             Huang Hong
       From the object-oriented viewpoint, the world consists of objects.
        Any given business function is supported by a set of objects that
        work together, or collaborate, to carry out the function. To do
        object-oriented analysis, we first define the set of objects that will
        make up the system. Then we describe how those objects work together.
        There are two parts to this description. First we must understand
        and describe the interactions or communication among the various
        objects. These interactions take the form of messages between
        objects. Second, we must describe the internal processing that goes
        on within each object to respond to messages from other objects,
        and to initiate messages to other objects.

Management information system        7_ 4                               Huang Hong
                       The Unified Modeling Language and the
                            Object Management Group

       UML(Unified Modeling Language) is an object-oriented modeling
        notation[表示法]. It is a successor to the modeling techniques
        found in Grady Booch’s Object Technology, James Rumbaugh’s
        Object Modeling Technique(OMT), Ivar Jacobson’s Object
        Oriented Software Engineering, and several other methods.
        Preliminary version was presented in 1995.
       OMG(Object Management Group, established in 1989) is a
        consortium[协会] of over 800 software vendors, developers and
        organizations that have combined theirs efforts to develop and
        propagate uniformity[一致] in object-oriented systems. OMG’s
        mission is to promote the theory and practice of object technology
        for the development of distributed computing systems. The goal is
        to provide a common architectural framework for object-oriented
        applications based on widely available interface specifications.
       UML have been submitted to OMG for consideration as a widely
        accepted standard for OO modeling.

Management information system       7_ 5                             Huang Hong
                      Object-Oriented Requirements
       Five separate but interrelated, object-oriented models or diagrams
        are used to define the system requirements. In some situations,
        only three or four diagrams may be required to specify the
        requirements accurately.
           1.   The class diagram
           2.   The use case diagram
           3.   The collaboration diagram
           4.   The sequence diagram
           5.   The statechart diagram

       OO Requirements = Event Table + Class Diagram +Use Case
        Diagrams + Interaction Diagrams(collaboration and/or sequence
        diagrams) + Statechart Diagrams

Management information system               7_ 6                    Huang Hong
               Object-Oriented Requirements(cont.)
       Use case diagram[用例图/使用实例图]
            A diagram to show the various user roles and how those roles use the system. It is a
             way to document the functions that a system must support. Sometimes a single,
             comprehensive use case diagram is used to describe the entire system. At other
             times, a set of smaller use case diagrams make up the use case model.
       Collaboration diagram[合作图]
            A diagram showing the objects that collaborate together to carry out a use case.
             Objects collaborate with each other by sending messages. Generally many
             collaboration diagrams are needed in a system’s requirements specification.
            Message: the communication between objects within a use case
       Sequence diagram[顺序图]
            A diagram showing the sequence of messages between objects during a use case. It
             contains the same information in a collaboration diagram, but emphasizes the
             sequence of the message rather than the collaborating objects.
       Interaction diagram[交互图]
            Both the collaboration diagrams and the sequence diagrams are referred to as
             interaction diagrams
       Statechart diagram[状态图]
            A diagram describe the states, states transition, and behavior of an object.

Management information system                 7_ 7                                          Huang Hong
            Requirements models for the traditional approach
                   and the object-oriented approach
               object-oriented approach            Events and                traditional approach
                                                   Event table


             Use case                Class                       Entity-relationship          Context
             diagrams               Diagram                           diagram                 diagram


             Sequence               Statechart
                                                                    Detail DFDs              Diagram 0
             diagrams               diagrams

                        Other OO                                                 Other
                         models                                                definitions

Management information system                    7_ 8                                               Huang Hong
                                The class diagram
       We often divide the description of a system into two categories:
        structural information and behavior information. Structural
        information means the component parts of the system. Class
        diagram provides the definition of the system components.
       Class diagram provide the structure for the database, and the
        structure of the computer program.
       Class diagram will also include user-interface classes which is
        called implementation classes.

Management information system       7_ 9                              Huang Hong
          The System Activities:An Object-Oriented Use Case/Scenario
       Use Case and Actors
              Use case[用例]
                 A single use or function performed by the system for those who use
                   the system. It is an activity the system carried out in response to an
              Actor [执行者]
                 A role played by a user of the system. A user can play several roles in
                   a system. An actor is always outside of the automation boundary of
                   the system.
                                               Connecting line to
                                               show which actors                     A use case
                                               participate in which
                       Stick                   use cases
       figure called a actor
       and representing a role
                                                                        Create new
                                 Order clerk

                                                    System automation

Management information system                            7_ 10                                    Huang Hong
       What is a scenario
            A scenario is a particular sequence of activities within a use case; a use case may
             have several different scenarios.
       An example of scenario for use case “create new order”

      Flow of activities for customer creates telephone order
           Main flow: The customer call RMO and talk to an order clerk. The order
             clerk verifies the customer information. If this is a first-time customer, a
             new customer record is created. The customer requests the first item for
             an order, this triggers the creation of a new order. The clerk verifies that
             the item is in stock and adds the requested quantity to the order. The
             customer then requests each item, and the clerk verifies it and adds it to
             the order. Finally, the customer provides payment information, and the
             clerk verifies it . The order is marked as ready, and the scenario ends.
           Exception conditions: If an item is not in stock, then the customer can choose
             not to order it or to put it on the order as a backorder item. If the
             customer credit is no good, then the order is put on hold until a check is
             received and cleared.
      Flow of activities for customer creates Web order
Management information system                 7_ 11                                        Huang Hong
                                The Use Case Diagram
       What is a use case diagram?
            A use case diagram is a graphical model that summarizes the information
             about the actors and use cases.
       What is the purpose of a use case diagram?
            It is used as a functional description of the entire system
       How to develop use case diagram
            To do use case analysis we look at the system as a whole and try to
             identify all of the major uses of the system.
            Use cases normally derive from[得自] the business events identified in
             the event table.

Management information system              7_ 12                               Huang Hong
                                The Use Case Diagram(continue)
               How to organize use cases in use case diagram
                   Use cases are normally organized in two ways:
                      Organizing the use cases by subsystem
                      Organizing the use cases By actor

                                                                                                     All use cases involving customers

                                                                                                                  look up item
                        Order entry subsystem
                                                                                                                                 create new order
                               Look up item                                                        <<uses>>
                 <<uses>>                        <<uses>>                                                                                       update order

                 <<uses>>                        <<uses>>                                                    <<uses>>
                                                                                                                                                look up order
                              create new order                                                                                                      status
                 <<uses>>                        <<uses>>
   customer                                                 order clerk                           <<uses>>
                                                                                                                                          create order return
                               update order

                                                                                                                            provide catalog
                                                                                                      update customer

Management information system                                       7_ 13                                                                           Huang Hong
                          The Use Case Diagram(continue)
       “Include” relationship between use cases
            What is a “include” relationship?
               One use case to use the services of another use case.
            An example of “include” relationship
               use case create new order includes use case validate customer account.
                      use case update order also includes use case validate customer account .
            In programming jargon[行话], use case such as validate customer account is
             referred to as common subroutine.

                                                        Create new order

                                                    >             <<includes>
                                look up item                           >

                                     <<includes>                validate customer
                                          >                          account
          Customer                                                                  Order clerk

                                                   Update order

Management information system                                   7_ 14                             Huang Hong
                    Use Case Diagram Vs Data Flow Diagram

       Similarity
            Like context diagram, a use case diagram helps define the scope of the
            The individual use cases identify individual functions just like DFD
       Differences
            Automation boundary is defined from the beginning of the use case
             diagram development. An actor must be the one who actually interacts
             with the system. But in the development of a DFD, the automation
             boundary often is not defined until the entire process has been detailed, an
             external agent is always the original source or destination of the
             information and may not necessarily be the one interacting with the
            Use case diagram does not indicate data flows.

Management information system             7_ 15                                   Huang Hong
                   Development of a use case diagram
       Two possible starting points:
            From event table
            Identify all actors who use the system as specific roles
       Once the actors and use cases have been identified, the next step is
        to develop a flow of activities as the starting point for identifying
        the various scenarios. As the different flows of activities are
          developed, any common internal use              cases can be identified
          and separated into different use cases.

Management information system             7_ 16                               Huang Hong
                           Object Interactions:
                   collaboration and sequence diagrams
   What’s the purpose of Interaction diagram?
       To describe the flow of information and interactions between objects.
       Interaction diagram is a low level diagram of the use case diagram
           use case diagram does not show the use case is performed by what objects and
             what information is passed to each other between these objects, but interaction
             diagram does.
   Two types of interaction diagram:
       Collaboration diagram
       Sequence diagram
   What’s similarities and differences between collaboration diagram and
    sequence diagram?
       Similarity:
           contain the same information
       Difference:
           Collaboration diagram: focus more the objects that interact together to support
             a use case. Top-down preferred analyst tend to draw collaboration diagram
             first to get an overview of the objects that collaborate to carry out the use case.
           Sequence diagram: focus more on the details of the messages. Bottom-up
             preferred analyst frequently develop sequence diagram and never even draw a
             collaboration diagram.
           Sequence diagram is more complex and is used more frequently in industry.

Management information system                   7_ 17                                         Huang Hong
             The relationship between use case, class and
                          sequence diagrams
                                                             Class diagram         Shipment
                        Use case diagram

        Order clerk                  order                                       Customer

                                       Sequence diagram for create new order
                      Create order
                                              :order                 :customer

                                                       Verify customer
        Order clerk

Management information system                     7_ 18                                       Huang Hong
           A sequence diagram for the telephone-order scenario
                   of the “create new order” use case
                                                                                        :product item              :inventory item
       customer          clerk
                            (Customer Information)    :customer

                               (CustomerName, PhoneNo)

            (Catalog No,Qty) [FirstItem]CreateOrder

                               AddToOrder(ProductID, Description, Qty)


                                                                                  (ProductID , Description, Qty)

                                                                            [QOH>Qty]CreateItem(itemID, Qty)                         :order item

                                       AdditemConfirmation( )

            FinishedOrdering    OrderComplete(Credit Card Number)                                   *ReadyToShip( )

Management information system                                       7_ 19                                                            Huang Hong
                    Steps to develop a sequence diagram
        Identify all the objects   and actors that are involved in the scenario.
             Use only actors who have been identified in the use case diagram. Use only objects
              from classes that are identified in the class diagram. If objects or actors are needed
              that have not been previously identified, then update those other diagrams.
        Based on the flow of activities, identify eachmessage that will be required to carry
           out the scenario. Identify both the source object or actor for the message and the
           destination object or actor.
           Identify source object
                 Identify the object that need the service
                 Identify the object that has access to the required input parameters
                 In a one-to-many association relationship from the class diagram, the one side
                   object usually send messages to the objects on the many side.
        Next determine whether each message is always sent or whether it is sent only under
         certain conditions.
        Sequence the messages correctly and attach them to the appropriate lifeline of the
           actors and objects.
       Add the formal syntax on the message to describe conditions, message names,
         and passed parameters
       If desired, add the response message and communications to make the sequence diagram
Management information system                7_ 20                                    Huang Hong
           A sequence diagram for the telephone-order scenario
                   of the “create new order” use case
                                                                                        :product item              :inventory item
       customer          clerk
                            (Customer Information)    :customer
                               (CustomerName, PhoneNo)

            (Catalog No,Qty) [FirstItem]CreateOrder

                               AddToOrder(ProductID, Description, Qty)


                                                                                  (ProductID , Description, Qty)

                                                                            [QOH>Qty]CreateItem(itemID, Qty)                         :order item

                                       AdditemConfirmation( )

            FinishedOrdering    OrderComplete(Credit Card Number)                                   *ReadyToShip( )

Management information system                                       7_ 21                                                            Huang Hong
                Iteration in Object-Oriented Approach

       Updating may required
            The use case diagram and flow of events(activities) are used to build the
             sequence diagram. The detail of the sequence diagram require the use of
             class diagram. As you build the sequence diagram, you may discover that
             the use cases, the flow of events, or the class diagram are incomplete
             and may require updating.
            One of the strengths of object-oriented development is that this
             interconnectedness helps to ensure that the final system is complete,
             comprehensive, and correct.

Management information system             7_ 22                                      Huang Hong
                                        Collaboration Diagrams
     Collaboration diagram is used to get a quick overview of the objects that collaborate
      to support a given scenario.
     A collaboration diagram uses the same symbols for actors, objects, and messages
      found in sequence diagram, but the lifeline symbol is not used, and a new symbol,
      the link symbol is used.
     Message syntax in collaboration diagram:
          [true/false condition]sequence number:return-value:=message-name(parameter-list)

                     An actor                                     An object which receives a
       who sends the initial                        message and sends other messages

                                1:FirstMessage( )                            2:SecondMessage( )

                                                           object1                                     object2
                            4:FinalResponse( )                             3:ReturnMessage( )

                                       A link between symbols                             A message arrow
                       that send or receive messages                       and descriptive name

Management information system                              7_ 23                                                 Huang Hong
                        Collaboration Diagram Example

                            1:Itemquery( )

           Customer   5:ItemAvailabilityInfo( )

                                        4:Productinfo( )      2:Productiteminquiry( )

                                                                      InventoryIteminquiry( )

                                                   Product item                                 Inventory item

                       Collaboration diagram for look up item availability

Management information system                         7_ 24                                                 Huang Hong
                                 Statechart Diagram
       What’s the purpose of a statechart diagram?
            Statechart diagram is used to describe the internal working or
              behavior of a object.
       Who needs a statechart diagram
            Each class in the class diagram of a system should have an unique
             statechart diagram.
       What’s the bases to build statechart diagrm
            Statechart diagram is built based on information from the class diagram
             and the sequence diagram.

Management information system            7_ 25                                   Huang Hong
               Terms and Symbols used in Statechart Diagram
       State
             A state for an object is a condition during its life when it satisfies some
              criteria, perform some action, or waits for an event.
       Action
             An activity performed by an object in a particular state.

                           State name                                              that must be
                                                                                   performed during
                                                                                   the period the state
                                idle                 working                       is active
                                                     Load part
                                                     Mill part
                                                    Unload part
                                                                                 concentric circles with the
                                                                   inside circle darkened denotes the final
                A darkened circle                                 state. This state indicate the exit from the
      denotes an initial state and          The state                statechart, frequently indicating the
   simply indicate the entry point to                               removal of the object from the system
             a statechart

Management information system               7_ 26                                               Huang Hong
                                Statechart diagram(cont.)
       Transition
              A component of a statechart that signifies[表示] the movement from one state to
               the next. A transition is represented by an arrow and a label to describe the
               components of the transition.

                Message event(transition name)                        Guard condition
                      The trigger for a transition                           A true/false test to
                      consisting of a message that has                        see whether a
    Origin            the properties of an event                              transition can be taken.        Destination
     state                                                                                                       state

                Off        OnButtonPushed [Bin not empty AND Safety cover closed]/                       On
                           Status:=self-test( ); ControlPanel.UpdateState(status)

                                      Action expression
                                             The statement on a
                                             transition to describe the
                                             action to be performed
Management information system                         7_ 27                                                   Huang Hong
                              Statechart diagram(cont.)
       Internal transition
            A transition within a state that does not remove the object from the state
            Three important internal transitions are used to define when action statements are
             executed within a state.
                Entry / action expression :activated at the moment that the object enters the state
                Do / action expression :executes while the object is within the state
                Exit / action expression :activated just before the object leaves the state

                                Idle                              Working
                                                               Entry/Load part
                                                                Do/Mill part
                                                               Exit/Unload part

Management information system                 7_ 28                                        Huang Hong
                                Statechart diagram(cont.)
       Messages, Transitions, and Actions
            Usually, transition names take the form of formal syntax which corresponds to the
             syntax of a message name:
             e.g. CreateItem(itemID,Qty)
       Message sending and dot notation
            Objects not only receive messages but send messages. Messages are normally sent
             as part of an action statement which in turn are part of transitions or states.
            To send a message, we normally use the syntax called dot notation.
                                ObjectName .MessageName(paramters,…)
             Object name
  or class name to which                              The milling machine铣床sent a message named
  the message will be                               Updatestatus() to a object called ControlPanel,with a
  directed                                                         parameter called status

               Off         OnButtonPushed [Bin not empty AND Safety cover closed]/            On
                           Status:=self-test( ); ControlPanel.UpdateState(status)

                           A part of a statechart of a milling machine object
Management information system                         7_ 29                                        Huang Hong
                             relationship among OO models

                                                                 Class diagram             Shipment
                        Use case diagram

        Order clerk                    order                                             Customer

                                         Sequence diagram for create new order
                      Create order                :order                 :customer
                                                           Verify customer
        Order clerk

                                                Items being                   Ready to
                                                   entered                      ship
                                       Statechart diagram for order class

                                     Relationship among OO models
Management information system                         7_ 30                                           Huang Hong
              Relationship between class, statechart and
                         sequence diagrams
                        Customer                        Order item
                                       Order class                    Product class
                          class                           class
      Create new
                            ×               ×               ×               ×
      Create new
      Check item

                 The columns identified all classes in the system, each row is for
       one sequence diagram, the ×s in the cells show which classes are
       involved in which sequence diagrams. A statechart for a class is based on
       the entire column for that class. Every cell with an × in it will provide
       information about the messages to and from the class and will impact the
       development of the statechart.

Management information system           7_ 31                                Huang Hong
                         Statechart diagrams(sample)

         CreateItem                                   Waiting      ShipItem
                        Exists      ReadyToShip( )                 (ItemID,Qty)   Shipped
         (ItemID,Qty)                                  to be

                                 Statechart diagram for order item object

  An order item is an passive object with a very simple life cycle.
       It comes into existence when an item is added to the order. While the
       order is being completed, it is in a “do nothing” state
       Once the order is completed, order item object moves to a state of
       “waiting to be shipped”
       Once the items have been shipped, the order item changes to a state of

Management information system                 7_ 32                                     Huang Hong
                                                                                                                            Completion transition: A transition

                      Statechart diagrams(sample)                                                                          with no trigger event so that it is taken
                                                                                                                            when the origin state completes its

                                                       Accepting items                                             Verifying payment
      CreateOrder(order information)/ Build
      order information; associate with                                            OrderComplete                   Do/ calculate total;
      customer                                                                     (CreditCard# )                    Verify Credit

                                                                                                                                 [Credit no good]
                                         AddToOrder(Product ID,Description,Qty)/                                                                        pseudostate
                                         InventoryItem.CheckQOH();                                              [CreditOK]
                                                         CreateOrderItem( )

                                 PullNextItem( ) [Item Available]        PullNextItem( ) [Item Not Available]
                                                   /Mark line                              /Mark line
                                 “shipped”                               “Backorder”

     Ready for fulfillment                                    Pulling items for         OrderShiped( )/ send                   shipped
                                                                  shipment              notice to customer
      Entry/ For Each
  OrderItem.ReadyToShip( );

                                                                                     CheckCleared( ) or CreditCleared( )

                                                                                            DeleteOrder( )

                                                     Statechart diagram for order object
Management information system                                         7_ 33                                                                    Huang Hong
                   How to develop statechart diagram
       To develop the statechart diagram of an object
            Identify all incoming message events across all sequence diagrams
             involving the object.
            Identify all output messages events across all sequence diagrams
             involving the object
           Brainstorms the possible states that might exist for the object.
                 The incoming message events help to identify transitions
                 Transitions are always connected to states
                 Insert appropriate intermediate state

Management information system             7_ 34                                 Huang Hong
                       Concurrent behavior of objects
       Path
            A valid sequence of transitions and status through a statechart
       Concurrent behavior
            An object can do multiple things in parallel, so within a statechart, there can
             be more than one active state at a time.
            An active path, particularly when multiple paths can be active concurrently, is
             called a thread.
       There are two types of notation to denote concurrent behavior in
        statechart diagram
            Composite state
            Synchronization pseudostate

Management information system             7_ 35                                   Huang Hong
               Composite state and Synchronization pseudostate

       Composite state(复合状态)
            A high level state with multiple compartments, each compartment
             contains a thread (has other states nested in it).


                                   State                       State

                                   State                       State

       Synchronization pseudostate(同步伪状态)
            Use solid vertical bar to split paths into multiple threads and merge
             multiple threads into a single thread.



Management information system              7_ 36                                     Huang Hong
             An RMO customer statechart diagram with concurrent threads

                                             PlaceOrder( )
                                                                         Inactive                       order
                   PlaceOrder( )
                                                                                 AfterNoOrder(1 year)


                                           StartNewYear/ Zero annual purchases

                             Regular                                                     Special
                   Do/ accumulate annual                                           Do/ accumulate
                         purchases           [annual purchases > 1000]           lifetime purchases
                      Do/ accumulate
                    lifetime purchases

                                                 PlaceOrder( )

                              Has                                                     Has
                          outstanding                                                 no
                             order              [Outstanding order]

                   ShipOrder( )
                                                      [No outstanding order]

Management information system                     7_ 37                                                     Huang Hong
                               An RMO customer statechart diagram
                                with Synchronization pseudostates

                         StartNewYear/ Zero annual purchases                              Special
                                                                                      Do/ accumulate
                                                                                    lifetime purchases
                      Do/ accumulate annual
                            purchases                     [annual purchases > 1000]
                         Do/ accumulate
                       lifetime purchases

      PlaceOrder( )                                                                                                  Inactive
                                                                                                    AfterNoOrder(1 year)

                             Has                     PlaceOrder( )                     Has
                         outstanding                                                   no
                            order                    [Outstanding order]

                                                           [No outstanding order]
                               ShipOrder( )

                                                     PlaceOrder( )

Management information system                          7_ 38                                                         Huang Hong
                                Statechart development
       Statechart is difficult for new analyst to develop, the primary problem is
        identifying the right states for the object. Another difficulty is to identify
        and handle composite states with nested threads. It may be helpful to
        pretend you are the object itself.
       Developing statechart need more iteration.
       Steps in developing state charts
            Review the class diagram and select the classes that will require statecharts.
            Identify all input messages across all sequence diagrams for the selected class.
            For each selected class, make a list of all states you can identify( usually by
            Build statechart fragments and sequence the fragments in the correct order to form
            Review the paths and look for independent, concurrent paths.
            Expand each transition with the appropriate message event, guard condition, and
             action-expression. Include with each state appropriate internal transitions and
            Review and test(desk checking) each statechart.

Management information system                7_ 39                                       Huang Hong

Shared By: