Docsity

Operation Contracts - Java and the Web - Lecture Slides, Slides of Java Programming

Partial preview of the text

Download Operation Contracts - Java and the Web - Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Use Case Model

Operation Contracts

 Create contracts for system operations.

Objectives

Why Contracts

  • Use cases are the primary mechanism in the UP to describe system behavior, and are usually sufficient.
  • However, sometimes a more detailed description of system behavior has value.
  • Contracts for operations can help define system behavior.

Domain Model And Contracts

  • A Domain Model is a visual representation of conceptual classes or real-world objects in a domain of interest.
  • Contracts describe detailed system behavior in terms of state changes to objects in the Domain Model, after a system operation has executed.

System Operations and

the System Interface

  • Contracts may be defined for system operations – operations that the system as a black box offers in its public interface to handle incoming system events. System operations can be identified by discovering these system events.
  • The entire set of system operations, across all use cases, defines the public system interface , viewing the system as a single component or class.

Example Contract:

enterItem

Operation: enterItem(itemID : ItemID, quantity : integer) Cross References: Use Cases: Process Sale Preconditions: There is a Sale Underway. Postconditions: -A SalesLineItem instance sli was created (instance creation) -sli was associated with the current Sale (association formed) -sli.quantity became quantity (attribute modification) -sli was associated with a ProductSpecification, based on itemID match (association formed)

Contract CO2: enterItem

Postconditions

  • The postconditions describe changes in the state of objects in the Domain Model. Domain Model state changes include instances created, associations formed or broken, and attributes changed.
  • Postconditions are not actions to be performed, during the operation; rather, they are declarations about the Domain Model objects that are true when the operation has finished.

The Spirit of Postconditions: The Stage

and Curtain

  • Express postconditions in the past tense, to emphasize they are declarations about a state change in the past. - (better) A SalesLineItem was created. - (worse) Create a SalesLineItem.

Writing Contracts Leads to Domain

Model Updates

  • New conceptual classes, attributes, or associations in the Domain Model are often discovered during contract writing.
  • Enhance the Domain Model as you make new discoveries while thinking through the operation contracts.

Contracts vs. Use Cases

  • The use cases are the main repository of requirements for the project. They may provide most or all of the detail necessary to know what to do in the design.
  • If the details and complexity of required state changes are awkward to capture in use cases, then write operation contracts.

Guidelines: Contracts

  • To make contracts:
    • Identify system operations from the SSDs.
    • For system operations that are complex and perhaps subtle in their own results, or which are not clear in the use case, construct a contract.
    • To describe the postconditions, use:
      • instance creation and deletion
      • attribute modification
      • associations formed and broken

The Most Common Mistake In Creating

Contracts

  • The most common problem in creating contracts 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 to include all the associations formed and broken.

Contracts, Operations,

and the UML

  • A UML operation has a signature (name and parameters), and also an operation specification, which describes the effects produced by executing the operation; the postconditions.
  • A UML operation specification may not show an algorithm or solution, but only the state changes or effects of the operation.

Operation Contracts

Expressed with the OCL

  • Associated with the UML is a formal language called the Object Constraint Language (OCL) [WK99], which can be used to express constraints in models.
  • The OCL defines an official format for specifying pre- and postconditions for operations, as demonstrated here: System::makeNewSale() pre: post: …