Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 50 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
50
Dung lượng
1,05 MB
Nội dung
5 Case study: coin-operated pay phone 182 Answer 5.10 Answer 5.10Answer 5.10 Answer 5.10 We will apply a few simple rules: • Public operations correspond to the names of messages sent by the actors. • Private operations correspond to the names of messages sent to oneself. • Attributes correspond to the names of persistent data, manipulated in the actions or conditions. Firstly, let’s take a look at the public operations. According to the dynamic context diagram (cf. Figure 5.7), we can identify: • pickUpReceiver • insertCoin(c) • dialNumber(num) • replaceReceiver • startComm •UT • lineState(state) • numberValidity(v) •endComm • diallingTimeout The state diagram (cf. Figure 5.20) leads us to add the following operation: •callTimeout Let’s now go through the private operations. The completed system sequence diagram (cf. Figure 5.5) showed the following messages: •checkCoin • incrementCredit • assess On the state diagram, we inserted the “do / transmitVoice” activity, which can be added to the list of private operations (as it is triggered indirectly by arrival in the 15_Chapter_05_Roques_NEW.fm Page 182 Friday, November 28, 2003 1:17 PM 5.4 Step 4 – In-depth description using a state diagram 183 “Communication” state). We will note that the checkCoin operation is conveyed by a “[c OK]” condition on the factorised internal transition. Finally, what are the interesting attributes? It is clear that an important item of information is that which is managed continuously by the pay phone: credit of the caller. As a result, we can eliminate the implicit operations of reading/writing this attribute (incrementCredit, assess). We now know enough to draw the extended static context diagram. Extended static context diagram Extended static context diagramExtended static context diagram Extended static context diagram An “extended static context diagram” is what we call a static context diagram in which we add attributes and operations of system level to the class that represents the system (conceived as a black box), as well as to non-human actors. We will note that we have made the public operations appear on the non-human actor, Switchboard, but not on the Caller actor. The concept of operation does not make sense on a human actor: we do not generally try to model him or her in a deterministic way. On a non-human actor, though, the list of operations represents its interface (in the sense of an API, for example) as it is used by the system in question. This is particularly useful to check the interoperability of the two systems, and to make sure that these operations are already available, or planned in the specifications. Figure 5.21 Extended context diagram Caller initial value public operations private operations <<actor>> Switchboard + routeNumber(num) + endComm() + diallingTimer() <<system>> Pay phone - credit = 0 + pickUpReceiver() + insertCoin(c) + dialNumber(num) + diallingTimeout() + numberValidity() + lineState(state) + callTimeout() + startComm() + UT() + endComm() + replaceReceiver() - checkCoin(c) - transmitVoice() 0 1 0 1 0 1 0 * 15_Chapter_05_Roques_NEW.fm Page 183 Friday, November 28, 2003 1:17 PM 5 Case study: coin-operated pay phone 184 As regards UML notation, let’s remember that: • “-” means private • “+” means public • “=” allows the initial value of an attribute to be specified. Bibliography BibliographyBibliography Bibliography [Booch 99] The Unified Modeling Language User Guide, G. Booch, J. Rumbaugh, I. Jacobson, Addison-Wesley, 1999. [Douglass 00] Real-Time UML: Developing Efficient Objects for Embedded Systems (2nd Edition), B. P. Douglass, Addison-Wesley, 2000. [Freeman 01] Designing Concurrent Distributed and Real-Time Applications with UML, P. Freeman, B. Selic, Addison-Wesley, 2001. [Mellor 91] Object Lifecycles: Modeling the World in States, S. Mellor, S. Shlaer, Prentice Hall, 1991. [Mellor 02] Executable UML: A Foundation For Model-Driven Architecture, S. Mellor, M. Balcer, Addison-Wesley, 2002. [Roques 99] Hierarchical Context Diagrams with UML: An Experience Report on Satellite Ground System Analysis, P. Roques, E. Bourdeau, P. Lugagne, in <<UML>>’98: Beyond the Notation, J. Bezivin & P. A. Muller (Eds), Springer Verlag LNCS 1618, 1999. [Rumbaugh 91] Object-Oriented Modeling and Design, J. Rumbaugh et al., Prentice Hall, 1991. [Rumbaugh 99] The Unified Modeling Language Reference Manual, J. Rumbaugh, I. Jacobson, G. Booch, Addison-Wesley, 1999. 15_Chapter_05_Roques_NEW.fm Page 184 Friday, November 28, 2003 1:17 PM 6 Aims of the chapter By working through several short exercises, this chapter will allow us to complete the overview of the main difficulties which are involved in constructing UML state diagrams, namely: • Continuous or finite activity – completion transition • Pseudo-event “after” • Concurrent regions • Entry/exit actions • Inheritance of transitions from the superstate • We have already dealt with sequence diagrams in Chapters 1 and 2, and we will go over collaboration diagrams in the section dedicated to design. Complementary exercises 6 16_Chapter_06_Roques_NEW.fm Page 185 Friday, November 28, 2003 1:16 PM 6 Complementary exercises 186 Alarm clock Let’s consider a simplified alarm clock: 1. We can set the alarm to “on” or “off”; 2. When the current time becomes that which is set on the alarm, the alarm clock rings continuously; 3. We can make the ringing stop. ** 6.1 Draw the corresponding state diagram. Answer 6.1 Answer 6.1Answer 6.1 Answer 6.1 Firstly, let’s take a look at the first sentence: 1. We can set the alarm to “on” or “off”. The alarm clock clearly has two distinct states: Unprepared (alarm “off”) or Prepared (alarm “on”). One action from the user enables it to change state. We assume that the alarm clock is unprepared at the start. Note the alarmTime parameter of the prepare event. Let’s now look at the other two sentences: 2. When the current time becomes that which is set on the alarm, the alarm clock rings continuously; 3. We can make the ringing stop. Figure 6.1 State diagram of sentence 1 Unprepared prepared (alarmTime) Prepared unprepare 16_Chapter_06_Roques_NEW.fm Page 186 Friday, November 28, 2003 1:16 PM Alarm clock 187 The occurrence of ringing forms a new state for the alarm clock. It involves a period of time, during which the alarm clock carries out a certain activity (ringing) that lasts until an event comes to stop it. The shift from the Prepared state to the Ringing state is triggered by a transition due to an internal change, represented by means of the « when » keyword. According to the problem statement, however, the return of the Ringing state to the Prepared state is only carried out on a user event. *** 6.2 Complete the preceding state diagram to account for the fact that the alarm clock stops ringing by itself after a certain amount of time. Answer 6.2 Answer 6.2Answer 6.2 Answer 6.2 There is therefore a second possibility of exiting the Ringing state: when the alarm clock stops ringing of its own accord after a certain amount of time. Continuous or finite activity – completion transition Continuous or finite activity – completion transitionContinuous or finite activity – completion transition Continuous or finite activity – completion transition An activity within a state can be either: • “continuous”: it only stops when an event takes place that makes the object exit from the state; • “finite”: it can also be stopped by an event, but in any case, it stops by itself after a certain amount of time, or when a certain condition is met. Figure 6.2 Preliminary state diagram of the alarm clock Unprepared prepared (alarmTime) Prepared when(currentTime = alarmTime) Ringing stopRinging unprepare 16_Chapter_06_Roques_NEW.fm Page 187 Friday, November 28, 2003 1:16 PM 6 Complementary exercises 188 The completion transition of a finite activity, also known as completion transition, is represented in UML without an event name or a keyword (as in activity diagrams). In our example, all we therefore need to do is add a ring activity to the Ringing state and a completion transition exiting this state. The completed state diagram is represented on the following figure. It is a good idea to wonder if the user has the right to ‘unprepare’ the alarm clock whilst it is ringing. In this case, we would have to add a transition triggered by unprepare and going directly from Ringing to Unprepared. ** 6.3 Deduce from the aforementioned points the extended static context diagram of the alarm clock (cf. 5.10). Figure 6.3 Completed state diagram of the alarm clock Unprepared prepared (alarmTime) Prepared when(currentTime = alarmTime) Ringing do/ ring activity stopRinging automatic transition unprepared 16_Chapter_06_Roques_NEW.fm Page 188 Friday, November 28, 2003 1:16 PM Alarm clock 189 Answer 6.3 Answer 6.3Answer 6.3 Answer 6.3 If we apply the rules again, which were stated in Answer 5.10, we easily obtain the diagram below. Digital watch Digital watchDigital watch Digital watch Let’s consider a simplified digital watch: 1. The current mode is the “Display” mode; 2. When you press once on the mode button, the watch changes to “change hour”. Every time you press the advance button, the hour is incremented by a unit; 3. When you press the mode button again, the watch changes to “change minute”. Every time you press on the advance button, the minutes are incremented by a unit. Figure 6.4 Extended static context diagram Figure 6.5 Simplified digital watch User <<system>> Alarmclock - currentTime = 00.00 - alarmTime = 00.00 + prepare(alarmTime) + unprepared() + stopRinging() - ring() 0 * Mode button Advance button 16_Chapter_06_Roques_NEW.fm Page 189 Friday, November 28, 2003 1:16 PM 6 Complementary exercises 190 4. When you press the mode button a third time, the watch goes back to “Display” mode. * 6.4 Draw the corresponding state diagram. Answer 6.4 Answer 6.4Answer 6.4 Answer 6.4 We easily obtain this typical state diagram, which is set out on the following figure. We can observe the notation in C++ or Java style that is used for the actions (to indicate that it is incremented by one): “hour++” and “minutes++”. UML does not yet offer an action language; we can therefore express the detail of the actions as we wish: free text, pseudocode, etc. We obtain self-transitions on the states for changes and not on the state for display. Does this mean that the “press advance button” event is impossible in the “Display” state? Of course not. Rather, this means that, as this event does not have any effect in this state, it does not trigger any transition. The event is purely and simply wasted. Figure 6.6 Preliminary state diagram of the digital watch Display press mode button press mode button press mode button Change minutes Change hour press advanced button / hour++ press advanced button / minutes++ 16_Chapter_06_Roques_NEW.fm Page 190 Friday, November 28, 2003 1:16 PM Alarm clock 191 **** 6.5 Add the following behaviour: when you press the advance button for longer than two seconds, the hours (or the minutes) are incremented quickly until the button is released. Envisage several possible solutions. Answer 6.5 Answer 6.5Answer 6.5 Answer 6.5 In the preceding example, the events of pressing the buttons actually corresponded to the indivisible pair of “press” and “release”. We had considered that the length of time spent pressing each button was trivial with regard to lengths of the states or, in any case, insignificant. With the new exposition, this is no longer the case, as the length of time spent pressing the advance button has an influence on the behaviour of the watch. The correct approach entails inserting a new event: “release advance button”, in order to be able to manage the time spent pressing the button. An initial and tempting solution consists in inserting a condition on the length of time spent pressing the button, as well as a new state called “Fast incrementation”, as illustrated on Figure 6.8. Figure 6.7 Conversion of an event into two Button pressed Button released Press / release advanced button Press advanced button Release advanced button Time 2sec 16_Chapter_06_Roques_NEW.fm Page 191 Friday, November 28, 2003 1:16 PM . operation: •callTimeout Let’s now go through the private operations. The completed system sequence diagram (cf. Figure 5 .5) showed the following messages: •checkCoin • incrementCredit • assess On the state diagram, we