CS387: The Models are the Code Lab Exercise 4 – Expressing Behaviour In principle, these exercises can be done using any drawing tool (even pen and paper!). However, using iUMLite is recommended to keep you used to the tool. In this exercise, you will look into some of the detail of specifying behaviour and operations. Full details can be found in Chapter 12 of Mellor and Balcer. We will look at specifying the behaviour within an Online Bookstore domain in a little more detail. I have stuck with the Action Language that is used in Mellor and Balcer. As mentioned in Lecture 8, the syntax of it differs from that used in iUMLite. But the meaning is the same. So please remember that there are many alternative Action Languages. But the differences are purely syntactic (e.g. you will see “across R1” written later, instead of the ASL version of “-> R1”). 1. First of all, open a new project and build the model below. It should give you some more practice at drawing models in iUMLite. Be sure to include the correct type definitions and show the identifier constraints. CS387 – Lab Exercise 4 2. Now we will first of all take a look at the state machine associated with the ShoppingCart class. Create a state machine for this class and first of all just type in the states and transitions as shown below. Be sure to include the creation and deletion states: Page 2 of 5 CS387 – Lab Exercise 4 3. Now we are going to add the signals to the state model. The event of receiving a signal will cause a state transition. Attach the signals as below, but note that this time we have added parameters to the signals. Do this by first modifying a transition by attaching a signal. Then RMB on the signal name and add parameters. Ensure that the types of the parameters match those of the respective attributes in the class diagram. Page 3 of 5 CS387 – Lab Exercise 4 4. The startCard signal will be generated by some entity external to the Shopping Cart. The first thing we need to do is to transfer the values of the parameters into the state machine and then update the order with this information (the product ID and number ordered). We can reference the values inside the first state in the usual object oriented fashion by considering the received event (“startCart(productID, quantity)” in this case) as an object. In the entry action, we will refer to “rcvd_evt” as this received event because it is possible that more than one kind of signal could cause a transition to be made into this state. All the entry action of the New Order state is going to do is to create a new signal, pass the parameter values to it and then send this signal to itself. This will then trigger the transition that will lead to the selection being added to the order. Edit the entry action to include the description below. Page 4 of 5 CS387 – Lab Exercise 4 5. Now we are going to relate the selected Product to the ShoppingCart via the ProductSelection association class. These are dynamic relations that only persist so long as the ShoppingCart is active. Once the user checks out, all these details are passed to an instance of the Order class. The details of the entry action for the Adding Selection to Order state are included below. Make sure you understand what is going on here! 6. And so it goes on. There is now a lot of detail. Take a look at Chapter 12 of the course book and make sure you can follow the behaviour of the whole state model. Page 5 of 5