Understanding Object Behaviors and Statechart Diagrams in Software Design

Slide Note
Embed
Share

Object behaviors and UML statechart diagrams play a crucial role in software requirements and design. State machines, transitions, events, and states are essential concepts in modeling object behavior in response to external events. By utilizing UML statechart diagrams, one can effectively represent the sequence of states an object goes through. This aids in understanding how individual objects change their state when triggered by events, thus facilitating the design of robust software systems based on defined behaviors and transitions.


Uploaded on Aug 01, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Object Behaviours UML Statechart Diagrams Software Requirements and Design CITS4401 Lecture 11 Based on lecture notes by Bruegge & Dutoit Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 1

  2. Finite state machine flip switch on Light on Light off flip switch off Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 2

  3. UML Statechart Diagrams A UML statechart diagram is a notation for describing the sequence of states an object goes through in response to external events. UML state machines are extensions of the finite state machine model. A state is a condition satisfied by the attributes of an object. A transition indicates a move from one state to another An event is a potential trigger for a change of state Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 3

  4. State machine Transition State flip switch on Light on Light off flip switch off Event Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 4

  5. Ex 1. Interaction with PC (V1) ctrl-alt-del Blue screen Login screen confirm-logout username-passwd Logout screen Active desktop request-logout Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 5

  6. UML Statecharts State machine models show how individual objects change their state in response to events. They are represented in the UML using statechart diagrams While sequence diagrams are used to model the combined behaviour of a group of objects in the system, the statechart diagrams are used to model the behaviour of a single object in response to external events. In the context of behaviour modelling, 2 different characterizations of states must be considered: 1.the state of each class, and 2.the state of the system as observed from the outside as the system performs its function. Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 6

  7. Interaction with PC (V2) Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 7

  8. UML Statechart Diagram Notation Event1(attr) [condition]/action State1 State2 do/action event/action Event trigger With parameters Guard condition entry/action exit/action Also: internal transitions UML notation based on statecharts by Harel in 1987 Added are a few object-oriented modifications A UML statechart diagram (or UML state machine) can be mapped into a finite state machine (FSM) Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 8

  9. Statechart Diagrams Graphs whose nodes are states and whose directed arcs are transitions labelled by events. States capture conditions which hold for a period of time e.g. light is on, light is off Events change the state (except internal) e.g. turning the light on, turning the light off Statechart diagrams represent behaviour from the perspective of a single object only An object model with a set of objects must be represented by a set of state diagrams Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 9

  10. State An abstraction of the attributes of a class State is the aggregation of several attributes of a class Basically an equivalence class of all those attribute values and links that do not need to be distinguished as far as the control structure of the system is concerned Example: State of a user interface screen logged in, logged out, active, idle active is an abstraction of all the user s logged in activity State has duration Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 10

  11. Event Something that happens at a point in time (e.g. button press, mouse click) Triggers a transition Internal transition (no state change) External transition (change to different state) May result in an action being executed Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 11

  12. Example 2: vending machine coins_in(amount) / set balance Collect Money coins_in(amount) / add to balance Idle cancel / refund coins [item empty] [select(item)] [change<0] do: test item and compute change [change>0] [change=0] do: dispense item do: make change Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 12

  13. Another example incidentDocumented incidentArchived incidentHandled States of the Incident object of FRIEND Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 13

  14. Problem Statement: Direction Control for a Toy Car Power is turned off Car stops and headlight goes out. Power is turned on Headlight shines Power is turned off Headlight goes out. Power is turned on Car runs forward with its headlight shining. Power is turned on Car moves forward and car headlight shines Power is turned off Car stops and headlight goes out. Power is turned on Headlight shines Power is turned off Headlight goes out. Power is turned on Car runs backward with its headlight shining. Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 14

  15. Toy Car: Dynamic Model Wheel Headlight Stationary Forward Stationary power on power off Off power power on off power off power on Stationary Stationary On power power off on Stationary Backward Stationary power on power off Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 15

  16. Practical Tips for Dynamic Modeling Construct dynamic models only for classes with significant dynamic behavior Avoid analysis paralysis Consider only relevant attributes Use abstraction if necessary Look at the granularity of the application when deciding on actions and activities Reduce notational clutter Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 16

  17. State Chart Diagram vs Sequence Diagram State chart diagrams help to identify: Changestoobjects over time Sequence diagrams help to identify The temporal relationships between objects over time Sequence of operations as a response to one or more events Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 17

  18. When to use state diagrams [Fowler] State diagrams are good at describing the behavior of an object across several use cases. State diagrams are not very good at describing behavior that involves a number of objects collaborating. Therefore it is useful to combine state diagrams with other techniques. If you do use state diagrams, don t try to draw them for every class in the system. it is almost always a waste of effort. Use state diagrams only for those classes that exhibit interesting behaviour, where building the state diagram helps you understand what is going on. Many people find that User Interface and Control objects have the kind of behaviour that is useful to depict with a state diagram. Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 18

  19. Review (1): Requirements Analysis Functional Modelling 1. What are the transformations? Create scenarios and use case diagrams Talk to client, observe, get historical records, do thought experiments 2. What is the structure of the system? Create object and class diagrams Identify objects. What are the associations between them? What is their multiplicity? What are the attributes of the objects? What operations are defined on the objects? Object Modelling Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 19

  20. Review (2): Requirements Analysis 3. What is its control structure? Create state diagrams Only for the dynamically interesting objects. Dynamic Modelling Create sequence diagrams Identify senders and receivers of events Show sequence of events exchanged between objects. Identify event dependencies and event concurrency. Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 20

  21. When is a model dominant? Functional model The model performs complicated transformations such as difficult computations consisting of many steps. Object model The system has non-trivial data structures. Dynamic model The model has many different types of events: Input, output, exceptions, errors, etc. Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 21

  22. When is a model dominant? Examples Compiler: Functional model most important. Dynamic model is trivial because there is only one type input and only a few outputs. Database systems: Object model most important. Functional model is trivial, because their purpose is usually only to store, organize and retrieve data. Spreadsheet program: Functional model most important. Object model is trivial, because the spreadsheet values are trivial and cannot be structured further. The only interesting object is the cell. Dynamic model is also relatively important. Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 22

  23. Recommended reading UML Distilled by Martin Fowler, Chapter 10 https://my.safaribooksonline.com/book/software-engineering-and- development/uml/0321193687 Object oriented software engineering by Bruegge & Dutoit Chapter 5 Software Engineering by Pressman Chapter 8, Section 8.5 Department of Computer Science & Software Engineering CITS4401 Software Requirements & Design | 23

More Related Content