Вы находитесь на странице: 1из 2

1

Example: The cinema model

We will demonstrate the usability of mOdCL with a model for part of a very simple tickets sale system for cinemas. In the following we show the class diagram, which will be used to create a module named CLASSES-CINEMA containing the Maude representation of the system and a sequence diagram, which can be used to generate a skeleton with the Maude representation of the system behavior. In the class diagram in Figure 1, a Cinema has a name and oers a number of sessions, for which it sells tickets, managing the payment with a single bank. A Session has a capacity, a ticket price, starting/ending times (startTime/endTime), and the tickets sold to clients. A Client knows some cinemas, pays with a debitCard and knows the tickets he has bought. The association class Ticket represents a ticket bought by a client for a given session; each ticket has a seat number. The Bank knows the accounts which support the debit cards, having each Account a given balance; accounts is modeled as a qualied association with the debitCard number as key.

Fig. 1. Class diagram for the cinema example.

Three public methods have been considered: goCinema, in the Client class, allows a client the purchase of a ticket for a given cinema, for a given time; buyTicket, in the Cinema class, allows to buy one ticket for the session starting at a given time; and pay, in the Bank class, allows to charge a given amount to the account associated to a given debitCard. We impose the avoid-overlapping invariant to the Client class, which states that a client cannot buy two tickets for overlapping sessions,
context Client inv : tickets -> forAll(T1 | tickets -> forAll(T2 | (T1 = T2) or (T1.session.endTime < T2.session.startTime) or (T2.session.endTime < T1.session.startTime))))

and the seats-in-session invariant, to the Session class, which states that the number of tickets sold for a session does not exceed its capacity

context Session inv : capacity >= tickets -> size()

The buyTicket method assumes as pre-condition that the cinema must oer a session at the requested time, and as post-condition that the returned value is either a null ticket or a new ticket, which is the only ticket added to the tickets of the requested session.
context Cinema::buyTicket(startTime:int, aClient:Client):Ticket pre : sessions -> select(S | S.startTime = startTime) -> size() = 1 . post: (result = null) or (sessions -> select(S | S.startTime = startTime).tickets -> includes(result) and ((sessions -> select(S | S.startTime = startTime).tickets) (sessions -> select(S | S.startTime = startTime).tickets @pre) ) -> size() = 1) .

Figure 2 shows a sequence diagram for the goCinema method. The diagram models the case in which, if there are tickets available and the payment succeeds, then a new ticket is created and returned as result; if there are no tickets available a null ticket is returned.

Fig. 2. Sequence diagram for the goCinema method.

Вам также может понравиться