13.8. Guidelines: Contracts

Apply the following advice to create contracts:

To make contracts:

1.
Identify system operations from the SSDs.

2.
For system operations that are complex and perhaps subtle in their results, or which are not clear in the use case, construct a contract.

3.
To describe the postconditions, use the following categories:

  • instance creation and deletion

  • attribute modification

  • associations formed and broken


Advice on Writing Contracts

  • State the postconditions in a declarative, passive past tense form (was …) to emphasize the declaration of a state change rather than a design of how it is going to be achieved. For example:

    • (better) A SalesLineItem was created.

    • (worse) Create a SalesLineItem.

  • Remember to establish a memory between existing objects or those newly created by defining the forming of an association. For example, it is not enough that a new SalesLineItem instance is created when the enterItem operation occurs. After the operation is complete, it should also be true that the newly created instance was associated with Sale; thus:

    • The SalesLineItem was associated with the Sale (association formed).

The Most Common Mistake in Creating Contracts

The most common problem is forgetting to include the forming of associations. Particularly when new instances are created, it is very likely that associations to several objects need be established. Don't forget!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.168.2