Specifying Operations
The effects or goals of use cases and operations can be described with OCL, abstracting away from the details of sequences of interaction and internal algorithms. Again, the advantage is that the more important issue of what we're trying to achieve can be written down Separately from the (Possibly Many) Ways of AchieVing IT.
For example:
Use case schedule job (Type: Jobcategory, C: Customer)
Post C.Jobs -> EXISTS (J: Job | j.category == Type and J.Date> = Today)
- The Jobs Attached to this Customer Now include One (Which We'll Call J Here) Whose Category Is of the Requested Type of Job (Fix Burst etc) and is scheduled for some time.
(SS -> EXISTS (x | p {x}) IS an OCL WAY OF SAYING That The COMES OUT TRUE for at Least One Member X of the set ss. Here We're Saying That, of All the Jobs Assigned to this Customer, There is at Least One Future Job of The Right Category.
NOTICE THAT
We do not have to restate things that are constrained by the type diagram and its accompanying invariants. So it's implicit that the new Job must be assigned a plumber with the appropriate skills (because of the "1" cardinality on the Job :: assignee association, and because of the invariant we wrote about skills). The postcondition relates together the states before and after the complete task of scheduling a job (or whatever) has been done --- no matter how long it takes, and no matter how many in-between stages there may be Negociating the date, assigning an available plumber all take time and various subsidiary operations and interactions between the business and the customer, and within any supporting software;. but we do not care about them at this level of description. A postcondition states what's required, but also leave things open. For example, we do not care which plumber is assigned, provided they have the relevant skills. Contrast this with writing program code, in which you w ould have to write some algorithm that would always end up choosing a specific one. This feature of postconditions is very valuable where there may be several different variants of the same basic behaviour which differ in detail. Different subtypes might have the same basic spec but additionally assign specific plumbers, or add extra criteria for their selection.A postcondition asserts a relation between the two states immediately before and after the operation or use-case has occurred. In an OCL postcondition, each attribute or association role-name can be suffixed with "@PRE" to refer to the prior state.
Snapshots can again help illustrate what the OCL is saying. For a postcondition, we need to show two states, before and after the operation has occurred. We use red (or thicker lines) for new associations, attribute values, and objects, and can Cross OUT ASSOCIATIONS AND TRIBUTE VALUES.HOW IS OCL PRACTILY USEFUL?
It's beeen found that, the more precisely you try to state them, the more you expose gaps and inconsistencies in your client's requirements Other ways of finding these holes are to animate scenarios or to get right on and write a prototype;. But the route to these can be quite long even in a RAD environment, and the benefit of the OCL is that you can write interesting things about high-level issues even before considering any software. OCL ensures that the requirement is unambiguous. The OCL statements act as the basis Of Test Harnesses for Any Software Written Subsequently.
We could write statements like our example invariant using a programming language such as Java This would seem particularly appropriate in view of the test-harness objective But OCL has two advantages..:
It's neutral about the implementation language. If several different software components are written within the same domain, you'll want to test conformity of each of them to the same set of rules. OCL is more succinct at dealing with sets, not needing explicit iterators Come Up a LOT.
Although working out the OCL statements can sometimes take longer (and a little practise) than the conventional requirements documents, the extra time is saved later, in a muh smoother coding phase, with all the big issues sorted out upfront.
Other Kinds of Ocl STATEMENT