A system sequence diagram shows the "confirm order" event as a single line.
From the picture alone, though, it is hard to know what confirming means.
Developers easily disagree about whether the order is created, whether inventory is reduced, or whether payment comes first.
To define the system event seen in the previous post precisely, you have to write down the state the system must be in when the operation finishes.
This is the
An operation contract is a document that defines the meaning of a system operation by its
preconditions
and
postconditions
.
It records the state that must hold before the operation runs, and the state that becomes true once it has finished.
An operation contract is a document that states what an operation
assumes and what it leaves behind as its result
.
An operation contract makes the functional requirements in a use case more precise.
If a use case says "the customer confirms the order," the operation contract explains what that changes inside the system.
The state that must hold before the operation starts
Postconditions
The state that becomes true after the operation finishes
A precondition is the basis on which the system can safely start the operation.
A postcondition is the basis for verifying the result of the operation.
With both conditions written down, developers and testers understand the same operation in the same way.
Three preconditions feed into the confirm order operation, and after the operation finishes, three postconditions become true
Postconditions are easiest to write completely when you check how the system's state changes under these four kinds.
Creation and deletion of instances
: a new order object was created, a cart item was deleted
Attribute changes
: the status of the order became confirmed, the stock quantity of a product decreased
Association formed
: the order and the customer were associated
Association broken
: the link between the cart and a product was removed
Thinking in terms of the concepts and relationships in the domain model makes these kinds easier to recall.
Each place where a relationship in the domain model changes becomes a postcondition.
Turning the order confirmation operation into an operation contract gives the following.
Item
Content
Operation
Confirm order (payment information)
Cross references
Place order use case
Preconditions
The cart has at least one product, the customer is logged in
Postconditions
An order object was created, the order status became confirmed, the order and the customer were associated
Postconditions do not describe implementation steps such as "the payment API was called."
Writing only the
resulting state
, that the order is confirmed once payment succeeds, keeps the contract valid even if the implementation changes.
๐
If a postcondition describes procedures, the contract turns into a design document.
Write it as "what becomes what state," and handle "how it is built" separately in the design stage.
of a system operation, so that the meaning of the operation is clear.
Postconditions can be written completely by checking how state changes in terms of creation, attribute changes, and forming and breaking associations.
Connecting the events in the system sequence diagram, the use cases, and the domain model through operation contracts reduces the chance that requirements are interpreted differently when they move into design.