oosunit2by tyagi

Upload: aamir42you

Post on 30-May-2018

242 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 oosunit2by tyagi

    1/16

    Devendra Singh Institue of Technology & Management

    Unit: 2:

    Dynamic modelling

    A System can best be understood by first examining its static structure

    ,structure of objects and their relationship to each other at a single moment in

    time .Now we e3xamine changes to the objects and their relationship over

    time .Those aspect of system that are concerned with time and changes are

    dynamic model.

    The major dynamic modelling concepts are

    1. Events

    2. External stimuli.3. States.Which represents value of objects?

    Difference between object diagram and state

    diagram.

    The state diagram is a standard computer science concept (graphicalrepresentation of finite state machine) has been handled in different waysdepending upon its use.

    A state diagram is a network of class and relationship.

    The dynamic model consists of multiple state diagrams for each class withimportant dynamic behavior, and shows the pattern of activity for anentire system.

    State and Events:

    The attribute values and link held by an object are called its state.

    An individual stimulus from one object to another is an object.

    The response to an event depends on the state of the object receiving it and

    can include a change of state or sending of another event to the original

    sender or to the third object. The pattern of events, states and state

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    2/16

    Devendra Singh Institue of Technology & Management

    transitions for a given class can be abstracted and represented as a state

    diagram.

    EVENTS-

    An event is something that happens at a point in time. for exampleuser depress left button or flight 123 departs from Chicago.

    An event has no duration.

    An event is simply an occurrence that is fast compared to thegranularity of time.

    One event may logically precede or follow another.

    Two events may be unrelated.

    Two events are causally related.

    Two events are causally unrelated are said to be concurrent .Theyhave no effect on each other.

    In modelling a system user do not try to establish an orderingbetween concurrent events because they can occur in any order.

    An event is one way transmission of information from one object toanother.

    An object sending an event to another object may expect a reply,butthe reply is separate event under the control of second object.

    Every event is unique occurrence, but can be grouped in a class ifthey all are of same type.

    An event conveys information from one object to another.

    Types of Events:1. SIGNAL EVENT: A signal is an explicite one way

    transmission of information from one object to another.while signal event is sending or receiving a signal.NOTE: A signal is a message between objects while a signalevent is an occurrence in time.

    FlightDeparture

    airline

    flightNumber

    city

    date

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    3/16

    Devendra Singh Institue of Technology & Management

    Change Event: A change event is an event that is caused by the satisfaction of

    Boolean expression. whenever the expression changes from false to true, the event

    happens.

    2. Time Event: A time event is an event caused by the occurrence of

    an absolute time or the elapse of a time interval.

    Example when(date= 19 oct 1988)

    after(10 seconds)

    STATES

    A state is the abstraction of the attribute values and links ofan i.e. the state of bank is solvent or insolvent.

    A state specifies the response of the object to input event.

    The response of the object of an object to an event may

    include an action or a change of state by the object. A state corresponds to the interval between two events

    received by an object.

    Events represent point in time.

    State represent interval of time.

    A state has duration; it occupies an interval of time. A state isoften associated with a continuous activity, such as ringingof a telephone, such as flying from Bombay to Delhi.

    Events and states are dual of one another.

    An event separates two states.

    A state separates two events.

    Condition- A condition is a Boolean function of object values .it isimportant to distinguish conditions from events which have no time

    duration. A state can be defined in terms of condition; conversely being

    in a state is a condition.

    Condition can be used as guards on transition. A guarded transition fires when its

    events occur, but only if the guard condition is true. For example, when you go

    out in the morning (event) if the temperature is below freezing (condition),put on

    your gloves (next state) a guard condition on a transition is shown by a Boolean

    expression in bracket following event name.

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    4/16

    Devendra Singh Institue of Technology & Management

    In the above figure [change

  • 8/9/2019 oosunit2by tyagi

    5/16

    Devendra Singh Institue of Technology & Management

    State diagram A state diagram relates events and states. When an event is received,

    the next state depends on current state as well as the event.

    A change of state caused by an event is called a transition.

    A state diagram is a graph whose nodes are states and whose directedarcs are transition labelled by event names.

    A state is drawn as rounded box containing an optional name.

    A transition is drawn as an arrow from the receiving state to targetstate.

    The label on the arrow is the name of event causing transition.

    States do not totally define all values of the object. A state diagram describes the behaviour of a single class of object.

    Since all instances of class have the same behaviour, they all share thesame state diagram.

    State diagram can represent one shot life cycle or continuous loops.

    One shot diagram represent objects with finite lives. A one shotdiagram has initial and final state.

    Figure given below is the state diagram for the following scenario-

    Use the following pattern to show action, activity and condition in state

    transition diagram.

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    6/16

    Devendra Singh Institue of Technology & Management

    entry and exit action is an alternative to showing action ontransitions, actions can be associated with entering or exiting a state.

    There is no difference in expressive power between the two notations

    , but frequently all transitions into a state perform the same action ,in

    which case attaching the action to the state is more concise.

    Following fig shows the control of a garage door opener .the user generates

    depress events with push button to open and close door .Each event reverse the

    direction of the door ,but for safety the door must open fully before it can be

    closed .the control generates motor up and motor down actions for the

    motor. The motor generates door open and door closed events when themotion has been completed .both transitions entering state, opening cause the

    door to open.

    fig shows the same model using actions on entry states. An entry action is

    shown inside

    Prepared By: Himanshu Kr. Tyagi

    State 1do/ activity

    event/effect

    State 2do/ activity

    event/effect

    event1(attrib)[cond1]/action 1

    Closed

    Opening

    Open

    Closing

    Depress/

    motor up

    Door

    open /motor

    Depress/mot

    or up

  • 8/9/2019 oosunit2by tyagi

    7/16

    Devendra Singh Institue of Technology & Management

    The state box following the keyword entry and / character .whenever the state

    is entered ,by any incoming transition ,the entry action is performed .An entry

    action is equivalent to attaching the action to every incoming transition .if anincoming transition already has an action , its action is performed first .Exit

    actions are less common than entry actions ,but they are occasionally useful. an

    exit action is shown inside the state box following the keyword exit and

    /character.

    Nested state diagram- The ways of structuring state machine are similar to the ways of

    structuring object: generalization and aggregation.

    Generalizations are equivalent to expanding the nested activities.

    It allows an activity to be described at high level than expanded at lowerlevel by adding details similar to the nested procedure call.

    Generalizations allow states and events to be arranged into generalizationhierarchy with inheritance of common structure and behavior, similar toinheritance of attributes and operations in class.

    Aggregation allows a class to be broken into orthogonal comments, similarto object aggregation hierarchy.

    Prepared By: Himanshu Kr. Tyagi

    Closed

    Entry/Motor Off

    Closed

    Entry/Motor

    up

    Closed

    Entry/ Motor Off

    Closed

    Entry/Motor down

  • 8/9/2019 oosunit2by tyagi

    8/16

    Devendra Singh Institue of Technology & Management

    Nesting state diagram-

    An activity in a state can be expanded as a lower level state diagram.

    Each state representing one step of the activity.

    Nested activities are one shot state diagram with input and outputtransitions, similar to subroutine.

    The set of nested state diagram from a lattice. fig below shows a toplevel vending machine .This diagram contains an activity dispense itemand an event select(item) that are expanded in more detail in nestedstate diagrams. The event coin in(amount) is written within thecollecting money state.

    Arm Ready

    Events can also be expanded into subordinate state diagram. Following fig shows

    the select item event from the first fig, which actually involves several low level

    events. The customer key in an item no can start our by hitting clear, his

    selection is confirmed by hitting enter.

    Prepared By: Himanshu Kr. Tyagi

    do/ move arm

    to correct row

    do/ move arm

    to correct

    column

    do/push item

    off shelf

    Arm ready

  • 8/9/2019 oosunit2by tyagi

    9/16

    Devendra Singh Institue of Technology & Management

    Aggregation concurrency:

    A dynamic model describes a set of concurrent objects each with itsown state and state diagram.

    The objects in a system are inherently concurrent and can changestate independently.

    The state of the entire system cannot be represented by a single statein a single object .it is the product of the states of all the objects in thesystem.

    A state diagram for an assembly is a collection of state diagrams, onefor each component.

    Aggregation implies concurrency.

    The aggregation state corresponds to the combined states of all thecomponent diagram.

    Example shows the state of car as an aggregation of component states.

    The ignition, transmission, accelerator and brake. each componentstate also has sub states. The states of car include one sub state fromeach component. Each component undergoes transitions in parallelwith all the other.

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    10/16

    Devendra Singh Institue of Technology & Management

    State generalization-

    A nested state generalization and event generalization on states.generalization is he or-relationship

    An object in the state in the high level diagram must be in exactly in onstate in the nested diagram.

    It must be in the first state or the second state or in one of the otherstates.

    The states in the nested diagram are all refinements of the states in

    the high level diagram. States may have sub states that inherit the transitions of their super

    states.

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    11/16

    Devendra Singh Institue of Technology & Management

    The above fig shows a state diagram for an automatic transmission. The

    transmission can be reverse, neutral or forward, if it is in forward, it can be

    first, second or third gear.

    State first, second and third are sub states of state forward .A super state is

    drawn as large rounded box enclosing all its sub states.substates in turn can

    further enclose further sub states.

    Event (Signal) generalization.

    Event can be organized into a generalization hierarchy with inheritance of

    event attributes, following fig shows part of tree input workstation.

    Event mouse button down, mouse button up inherits location frommouse button.

    Keyboard characters can be divided into control characters and graphiccharacters.

    Ultimately every actual event can be viewed as a leaf on ageneralization tree of events.

    (Draw figure by yourself)

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    12/16

    Devendra Singh Institue of Technology & Management

    Scenario-

    A scenario is a sequence of events that occur during one

    particular execution of a system. The scope of scenario can vary; it

    may include all events in the system, or it may include only those

    events generated by certain objects in the system. A scenario can be

    the historical record of executing a system or a experiment of

    executing a proposed system. Following figure shows a scenario for

    using telephone line. This scenario only contains events affecting the

    telephone line-

    Scenario for a phone call

    Caller lifts receiver

    Dial tone begins

    Caller dials digit

    Dial tone ends

    Caller dials digit

    Caller dials digit

    Caller dials digit

    Specified phone rings Callee answers phone

    etc.Event trace diagram-

    Each event transmit information from one object to another e.g. ,

    dial tone begins transmits a signal from the phone line to caller, the

    next step after writing the scenario is to identify the sender and the

    receiver object of each event. The sequence of events and objects

    exchanging events can both be shown in an augmented scenario

    called event trace diagram. This diagram shows each object as a

    vertical line and each event as a horizontal arrow from sender objectto receiver object. Time increase from top to bottom, it is only

    showing sequence of events not their exact timing.

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    13/16

    Devendra Singh Institue of Technology & Management

    (b) A simple digital watch has a display and two buttons to set it ,the A button

    and the B button .the watch has two modes of operation ,display time and set

    time .in the display time mode ,hours and minutes are displayed ,separated by a

    flashing colon .the set time mode has two sub modes ,set hours and set

    minutes , the button A is used to select modes .each time it is pressed ,the

    mode advances in the sequence : display, set hours ,set minutes ,display

    etc.within the sub modes ,the B button is used to advance the hours or minutesonce each time it is pressed. Buttons must be released before they can generate

    another event .prepare a state diagram of watch.

    Ans-A state diagram for a simple watch is shown in the fig .we assume that a

    button is an event and that we may ignore the release of a button .we use

    diagram to refer to pressing the A button and B button to refer to pressing the B

    button.

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    14/16

    Devendra Singh Institue of Technology & Management

    State diagram for simple digital watch

    automatic transition

    Frequently the only purpose of a state is to perform a sequential activity .when

    the activity is completed, a transition to other state fires. An arrow without an

    event name indicates an automatic transition that fires when the activity

    associated with source state is completed. If there is no activity ,the unlabeled

    transition fires as soon as the state is entered .if a state has one or more

    automatic transition ,but none of the guard conditions are satisfied ,then the

    state remains active until one of the conditions is satisfied or until an event

    causes another transition to fire.

    How is concurrency within states of single object represented?

    Ans- concurrency within the state of a single object arises when the object

    can be partitioned into subsets of attributes or links, each of which has its

    own subdiagram.the state of the object comprise one state from each sub

    Prepared By: Himanshu Kr. Tyagi

    Digital watch

    A A

    Display

    timedo: show

    hours

    And minutes

    Set

    hoursdo: show

    hours

    Set

    minutesdo: show

    minutes

  • 8/9/2019 oosunit2by tyagi

    15/16

    Devendra Singh Institue of Technology & Management

    diagram. The sub diagram need not be independent; the same event can

    cause transition in more than one diagram.

    Concurrency within single composite states of an object is shown by

    portioning the composite state into sub diagrams with dotted lines .Thename of the overall composite state can be written in a separate region of

    box; separated by solid line from the concurrent sub diagram.

    Explain initial sate and final state.

    Ans-

    Initial state is entered on creation of an object.

    Entering the final state implies the destruction of the object .

    An initial state is shown by the solid circle.

    A final state is shown by the bulls eye.

    The dynamic model is the collection of state diagram that interact

    with each other via shared events.Dynamic model represents the

    control structure of system.

    internal actions:

    Ans-An event can cause an action to be performed without causing a state

    change. the event name is written inside the state box followed by a/ and the

    name of action (keywords entry, exit and do are reserved words within the state

    box) when use an event occurs its action is executed but not the entry or exit

    action for the state. There is therefore a difference between an internal action

    and a self transition; the self transition cause the exit and entry actions for the

    Prepared By: Himanshu Kr. Tyagi

  • 8/9/2019 oosunit2by tyagi

    16/16

    Devendra Singh Institue of Technology & Management

    state to be executed. Following fig shows an internal action within collecting

    money state.

    Prepared By: Himanshu Kr. Tyagi

    State1do:

    activity1

    entry/action

    2

    exit/action3

    event/actio

    n4

    State2do:activity1

    entry/action2

    exit/action3

    event/action

    Object

    class

    Event1(attrib)[cond1]/action event

    2 (attrib)