/
Selected topics in programming theory Statecharts M ngeles Martnez Ibez University of Selected topics in programming theory Statecharts M ngeles Martnez Ibez University of

Selected topics in programming theory Statecharts M ngeles Martnez Ibez University of - PDF document

mitsue-stanley
mitsue-stanley . @mitsue-stanley
Follow
548 views
Uploaded On 2014-12-21

Selected topics in programming theory Statecharts M ngeles Martnez Ibez University of - PPT Presentation

Introduction 2 When to use Statecharts 3 Basic components 4 Connectors and compound transitions 5 Concurrent Statecharts 6 Hierarchy of States 7 Bibliography Selected topics in programming theory 1 INTRODUCTION Definition Statecharts are used to des ID: 27454

Introduction When

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Selected topics in programming theory St..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Selected topics in programming theory Statecharts MªÁngeles Martínez IbáñezUniversityofBergen Selected topics in programming theory INDEX 1.-Introduction2.-Whentouse Statecharts3.-Basic components4.-Connectorsandcompoundtransitions5.-ConcurrentStatecharts6.-HierarchyofStates7.-Bibliography Selected topics in programming theory 1.-INTRODUCTION Definition:Statechartsare used to describe the behaviour of a system and describe all of the possible states of an object as events acting upon it.  \n  \r   \n \r\r \n \r \n Simple example–MicrowaveStateChart- Selected topics in programming theory 1.-INTRODUCTION As it’sseen, Statechartsare finitestatemachines extended withhierarchyandparallelism, allowinga complexsystemtobe expressedin a more compact way.Statechartsdescribe how the functionality of a system relates to the state in which it exists at any one point in time, and how its state changes in response to events acting upon it. It relates things happening to an object to changes in the object. Selected topics in programming theory 2.-Whentouse Statecharts Use statechartsfor classes where it isnecessary to understand the behaviour of theobject through the entire system. Not all classes will require a statechart, andthere aren’t useful for describing thecollaboration of all objects in a use case.Statechartsare other combined with otherdiagrams such as interaction diagrams andactivity diagrams. Selected topics in programming theory 3. BASIC COMPONENTS States they’rerepresentedby roundedboxesandshow thestateoftheobject. Thearrowbetweenstatesindicates the transition. Selected topics in programming theory 3. BASIC COMPONENTS Allthediagramsbeginwitha “startstate”andendswitha “final state”. It’snotobligatoryuse exactlyoneofeachtype.Wecan havediagramswithoneormore “startstate”andwithno “final state”. Isverycommonfindsystem’sbehaviourwhichneverends. Selected topics in programming theory 3. BASIC COMPONENTS -� And-states : Haveorthogonalcomponentsthatare relatedby “and”. They’rerepresentedgraphicallyas roundedrectangles(parentstate) dividedby dashedlines-� Or-states : Thisis, ifthestateofthehighlevelisactive, onlyoneoftheinternalstateswillbe active. Selected topics in programming theory 3. BASIC COMPONENTS Selected topics in programming theory10 Selected topics in programming theory11 3. BASIC COMPONENTS Transition they’rerepresentedby anarrowfromonetootherstate. Selected topics in programming theory12 3. BASIC COMPONENTS Self-Transition : thatisa transitionwhichgoesback tothesamestate. Example–Elevator- Selected topics in programming theory13 3. BASIC COMPONENTS Defaulttransition : specifiedby a smallarrowemanatingfroma smallsolidcircle. Selected topics in programming theory14 Selected topics in programming theory15  Triggers Triggersare thedynamicelementsin statecharts. Triggerscause statetransitionsorstaticreactions. Events, conditionsora combinationofbothcan be triggers. Triggersrepresentedgraphicallyas directedgraphs(arrows), connectingtwostates. 3. BASIC COMPONENTS Selected topics in programming theory16 -� Events : Eventssignifya precise instantin time; theyare edge-sensitive, comparable tosignalsandinterrupts. Eventscan be generatedexternallytothestatechart(primitiveevents) orinternally.Sourcesforinternallygeneratedeventsare actions, timeoutsorsensorsfordetectingthestatus ofstates, activities, conditionsanddata items. 3. BASIC COMPONENTS Selected topics in programming theory17 Selected topics in programming theory18 Eventsmay alsobe a compoundsetofothereventsandconditions. Eventsare representedas a alphanumericlabelsontransitionlinesorin theOnfieldin statedefinitions. 3. BASIC COMPONENTS Selected topics in programming theory19 Thenegationofaneventusingthenotoperationmustbe approachedwithcaution. Thisnegationmeansthatthespecifiedeventdidnotoccur.Eventexpressionsare evaluatedaccordingtotheconventionalprecedencerules oflogicaloperations, andparenthesescan be used. 3. BASIC COMPONENTS Selected topics in programming theory20 3. BASIC COMPONENTS    Example-Negatinganevent- Selected topics in programming theory21 Theanyoperatorisusedtodetectthefactthatsomeunspecifiedcomponentofaneventarrayhas occurred.Thealloperatorcaptures thesimultaneousoccurrenceofalleventsin thearray. 3. BASIC COMPONENTS Selected topics in programming theory22 -� Conditions : Conditionsare booleanexpressions, valuedTRUE orFALSE, thatsignifya time spanduringwhichtheconditionholds. Conditionscan be edgeorlevel-sensitive. Conditionsmay be primitiveelementsorcompoundelementsthatexpressa setofbooleanoperationssuchas AND andOR. 3. BASIC COMPONENTS Selected topics in programming theory23 Conditionsare representedas alphanumericlabelsontransitionlines, enclosedin bracketsin theformeventtcondition, orin theTriggerfieldin statedefinitions. 3. BASIC COMPONENTS exp1 = exp2, exp1 # exp2exp1 � exp2,exp1 exp2exp1 = exp2,exp1 &#x-2.3;䕱= exp2Comparisonconditions Selected topics in programming theory24 Selected topics in programming theory25 -� Data-itemexpressions : A data-itemisa unitofinformationthatmay assumevaluesofvarioustypesandstructures. They’resimilar tothedata elementsin conventionalprogramminglanguages: variables, constants, andso on. Theymaintaintheirvaluesuntilthey’reexplicitlychangedandassignednewvalues. 3. BASIC COMPONENTS Selected topics in programming theory26 Knowingthis, data-itemexpressionscan be usedin assignmentactions, andcan be ofdifferenttypes: numeric(integer, real, bit, bit-array), strings, andstructured.WithnumericexpressionsIt’sallowtouse userfunctions(functionsthatare notpredefined) 3. BASIC COMPONENTS Selected topics in programming theory27 Selected topics in programming theory28  Actions Actionsare instantaneousoperationsandare performedas a resultofsometrigger. Changingthevalueofa conditionordata-itemandinvocationsofactivitiesare examplesofactions. Anactioncan alsobe a sequenceofactionsthatoccursimultaneouslyregardlessofthesequenceoftheirappearance. 3. BASIC COMPONENTS Selected topics in programming theory29 Logicalconditionalactionsmay be expressedbasedonconditionsorontheoccurrenceofevents. Actionsare representedas alphanumericlabelsonthetransitionlines, separatedby a slashin theformeventtcondition]/action, orin theActionfieldin statedefinitions. Whenanactionisa sequenceofactions, theactionsthatmakeitup are separatedby semicolons. 3. BASIC COMPONENTS Selected topics in programming theory30 Selected topics in programming theory31 Ifwe’reworkingwithtextual language, thisallowsvarioustypesofactionsclassifiedas follows:  Basic actionsthatmanipulateelements.  Conditionalanditerativeactions. 3. BASIC COMPONENTS Selected topics in programming theory32 -� Elementmanipulation : Itcausingchangesthatcan be checkedandtriggeringotherhappeningsin thesystem.Theelementswhichare manipulatedby mostbasicactionsare: events, conditionsanddata-items. 3. BASIC COMPONENTS Selected topics in programming theory33 3. BASIC COMPONENTS Eventmanipulation: isjustsendingtheevent. Thisisperfomedby theactionthatissimplythenameoftheevent.Conditionmanipulation: specialactionscan cause a conditiontobecometrueorfalse.Wecan findmanyabbreviationsforthis. Selected topics in programming theory34 A conditionhas twoassociatedevents:tr(C) changesfromfalsetotrue.fs(C) changesfromtruetofalseAnactionhas thisevents:tr!(C) setthetruthvalueofconditionC totruefs!(C) itcorrespondswiththeactionmake_false(C), and, obviously, setittofalse. 3. BASIC COMPONENTS Selected topics in programming theory35 It’susual tothinkthat, tr(C) alwaysoccurwhentr!(C) isexecuted, butthisisn’tcorrect. TheeventsoccuronlywhenthetruthvalueofC changesvalue, buttheactionscan be executedwithoutchangingthetruthvalueifti wasthedesiredonetostartwith. 3. BASIC COMPONENTS Selected topics in programming theory36 Data-itemsmanipulation: alltypesofdata-itemscan be involvedin assignments. Theright-handsideexpressionoftheassignmentmustbe typeconsistentwiththeassigneddata-itemontheleft-handside. Bothsidesmustbe eithernumericorstring. 3. BASIC COMPONENTS Selected topics in programming theory37 -� Compoundactionsandcontextvariables : It’spossibletoperformmore thanoneactionwhena transitionistaken. Ifwewanttodo this, we’vetowriteitby separatingthecomponentactionsby a semicolon.Theconditionalactionisotherkindofcompoundaction, in thichtheactual actioncarriedout dependsona conditionoranevent. 3. BASIC COMPONENTS Selected topics in programming theory38 Wecan findtwocases:ifC thenA elseB endifwhenE thenA elseB endwhen 3. BASIC COMPONENTS Actions Condition Eventexpression Selected topics in programming theory39 -� Iterativeactions : Theyhavebeendeclaratedtohelpmanipulatearrays.forI in N1 toN2 loopendloop 3. BASIC COMPONENTS Selected topics in programming theory40 Theactionbreak, willskiptherestofloop’siterations, andtheactionthatfollowstheloopconstructwillbe thenextonetoexecute.Thewhileloopiteratesuntilsomeconditionbecomesfalse. Wecan use thebreakactionheretoo, tojumpout oftheloopwithoutcompletingtheiteration. 3. BASIC COMPONENTS Selected topics in programming theory41  Activities Activitiesare operationsthatare performedin a non-zeroamountoftime. Activitiescan be controlled(startedorstopped) throughactions, andtheirstatus can be monitored. Activitiesare notrepresentedgraphicallyin statecharts. Theymay appearas partofotherelementdefinitions. 3. BASIC COMPONENTS Selected topics in programming theory42 Selected topics in programming theory43 4. CONNECTORS AND COMPOUND TRANSITIONS ConnectorsandCompoundTransitions : theyare usedtohelpeconomizein arrowstoclafirythespecification. Selected topics in programming theory44 4. CONNECTORS AND COMPOUND TRANSITIONS -� Conditionconnectors : AlsocalledC-connectors. Theyare representedgraphicallyas circlescontainingtheletterC. Ifdistinctconditionsapplytotheoutboundtransitionarrows, theymustbe exclusive in ordertopreventnondeterminism.      Selected topics in programming theory45 4. CONNECTORS AND COMPOUND TRANSITIONS -� Swtichconnectors : AlsocalledS-connectors. Theyare usuallyusedwitheventsratherthanconditions, butthepurposeisthesameonethatwiththeC-connector. Selected topics in programming theory46 4. CONNECTORS AND COMPOUND TRANSITIONS -� Junctionconnectors : Transitionarrowscan be joinedusingthiskindofconnectors. Wecan findeventswhichcauses exitfromtwostatesand, in theotherhand, thecase in whichtwoeventsleadout ofa stateintotwoseparatestates. Selected topics in programming theory47 4. CONNECTORS AND COMPOUND TRANSITIONS -� Diagramconnectors : Theyare usedforeliminatinglengthyarrowsfromthechartin favor ofmarkingtwopointsin thechartandindicatingthatthearrowflowsfromonepointtotheother. Isusefulfordo symbolicreferencetoanotheroccurrenceofthesamesymbolin anotherdiagram, allowingforconnectionsamongseparatediagrams. Selected topics in programming theory48 -� Historyconnector : AlsocalledH-connector. It’sfeatureistoenterthestatemostrecentlyvisitedwithinthegroupofstates(thisisobtainedby the“historyentrances”).Ifwewanttoextenda historyentrancedowntoalllevels, theH-connectorcan appearwithanasteriskattached(thisisa deephistoryconnector). 4. CONNECTORS AND COMPOUND TRANSITIONS Selected topics in programming theory49 4. CONNECTORS AND COMPOUND TRANSITIONS Example–statechartwithhistoryconnectorforaccount- Selected topics in programming theory50 4. CONNECTORS AND COMPOUND TRANSITIONS Example–ifthesystemwaslastin “operating.fast”, thenthatwouldbe thestateentereddespitethefactthat“slow”istheinitialstate.- Selected topics in programming theory51 4. CONNECTORS AND COMPOUND TRANSITIONS Fork : Wemay viewthisas anotherkindofcompoundtransition. Thistransitionsplitstheexecutionflowintotwoormore parallelactivities. -ExampleUML Notation- Selected topics in programming theory52 3. BASIC COMPONENTS -ExampleJoin&Fork- Selected topics in programming theory53 Whenwetalkaboutthat, statechartssupportconcurrent, wereferthatin thesamestatechart, itcan be more thanonestateexecutingsimultaneously.Whentheorderleavestheconcurrentstates, it’sin onlya single state.Concurrentstatediagramsare usefulwhena givenobjecthas setsofindependentbehaviors. Buttheyare notveryadvisable. 5. CONCURRENT STATECHARTS Selected topics in programming theory54 5. CONCURRENT STATECHARTS Selected topics in programming theory55 6. HIERARCHY OF STATES Thereasontouse thisisbecausethehighlycomplexbehaviorcannotbe easilydescribedby simple diagrams.Statechartcan finishbeinga chaoticsuccessionofstatesandtransitions.Theuse ofa hierarchicschemeoffersa solutiontothisproblem. Selected topics in programming theory56 6. HIERARCHY OF STATES      A simple state-transitiondiagramwithouthierarchy Selected topics in programming theory57 6. HIERARCHY OF STATES     V V F Clusteringofstatesofthelas example.Thesemanticistobe in V istobe, exclusively, in eitherofitssubstates, S orT. Thisistheclassicalexclusive-orappliedtostates.V iscalledanor-state, andit’sparentofthetwosiblingstatesS andT. Selected topics in programming theory58 SUMMARY Statechartdiagramsisa graphthatrepresentsa behavior’sstatemachine.  A stateisa conditionduringthelifeofanobjectoraninteractionduringwhichitsatisfiessomecondition , performssomeaction , orwaitsforsomeevent . Selected topics in programming theory59 SUMMARY Aneventisanoccurrencethatmay triggera statetransition.  A transitionisa relationshipbetweentwostatesindicatingthatanobjectin thefirststatewillenterthesecondstateandperformspecificactionswhena specifiedeventoccursprovidedthatcertainspecifiedconditionsare satisfied. Selected topics in programming theory60 SUMMARY Thetriggerfora transitionistheoccurrenceoftheeventlabelingthetransition. Ifaneventdoesn’ttriggeranytransition, it’sdiscarded.  A conditionisanexpressionwhichdecides whethera statetransitionactuallyoccurs.  Anactionare associatedwithtransitionsandare consideredtobe processesthatoccurquicklyandaren’tinterruptible. Selected topics in programming theory61  Activitiesare associatedwithstatesandcan takelonger. Anactivitymay be interruptedby someevent. SUMMARY Selected topics in programming theory62 7.-Bibliography [FS98]M. Flower, K. Scott: “UML Distilled. SecondEdition. A BriefGuidetotheStandard ObjectModelingLanguage”, AddisonWeslyProfessional.[HM98]D. Harel, M. Politi“ModelingReactive SystemswithStatecharts. Thestatemateapproach”, McGraw-Hill, NewYork, Unitedstates[Op97] http://www.opengroup.org/ [In02] http://www.informatik.uni-freiburg.de/ [De02] http://dependable.kaist.ac.kr/ Selected topics in programming theory63 7.-Bibliography [Iv04] http://www.iv.cs.tu-berlin.de [Cs] http://www.cs.uiowa.edu/ [Cs] http://www.cs.sjsu.edu/