Object Design: Specifying Interfaces

References:

  1. Bernd Bruegge and Allen H. Dutoit, "Object-Oriented Software Engineering", Third Edition, Chapter 9

9.1 - Introduction: A Railroad Example

9.2 - An Overview of Interface Specification

Interface specification includes the following activities:

9.3 - Interface Specification Concepts

Principal concepts of interface specification:

9.3.1 - Class Implementor, Class Extender, and Class User

9.3.2 - Types, Signatures, and Visibility

9.3.3 - Contracts: Invariants, Preconditions, and Postconditions

The contract paradigm of programming states that those who invoke ( call ) an operation are responsible for ensuring the pre-conditions, and the implementor of the operation is responisble for ensuring the post-conditions only when the pre-conditions are met. The class implementor has no responsibiltiy for handling cases in which the pre-conditions are not met, and anything could "legally" happen in that case. Obviously the class implementor is responsible for clearly documenting the necessary pre-conditions for the class. This approach to programming eliminates redundant error checking, and clearly identifies who is responsible for what, but can lead to uncaught errors if the pre-conditions are not specified clearly or if the programmer who invokes the method does not check the pre-conditions carefully. ( It also requires that the method invoking the class method be able to check the pre-conditions. )

9.3.4 - Object Constraint Language

Boolean expressions which evaluate to true or false. OCL can be attached to class diagrams as notes:

Or as text expressions:

9.3.5 - OCL Collections: Sets, Bags, and Sequences

Special operations for working on collections:

The length of a Tournament must not exceed one week: ( attribute, Dot notation )

Only players enrolled in the League may play in a Tournament: ( collection, Arrow notation )

The active players in a League are all players playing in at least one Tournament: ( collection, Arrow notation )

9.3.6 - OCL Quantifiers: forAll and exists

9.4 - Interface Specification Activities

9.4.1 - Identifying Missing Attributes and Operations

9.4.2 - Specifying Types, Signatures, and Visibility

9.4.3 - Specifying Pre- and Post conditions

9.4.4 - Specifying Invariants

9.4.5 - Inheriting Contracts

9.5 - Managing Object Design

9.5.1 - Documenting Object Design

Two primary challenges:

Three main approaches to developing the Object Design Document:

9.5.2 - Assigning Responsibilities

9.5.3 - Using Contracts During Requirements Analysis

Tradeoffs to consider regarding how early to introduce constraints into the development process:

9.6 - ARENA Case Study

9.6.1 - Identifying Missing Operations in TournamentStyle and Round

Different styles of tournaments have different rules for assigning players to matches. For example a knock out style cannot assign players to matches in the next round until the winners of the current round are known, whereas round robin style can assign all players to all matches as soon as the number of players is known. Either style may or may not have restrictions on the number of players, such as requiring a power of two for knockout style.

New requirements:

This leads to a new class, Round, and a new set of methods in the TournamentStyle class.

9.6.2 - Specifying the TournamentStyle and Round Contracts

9.6.3 - Specifying the KnockOutStyle and KnockOutRound Contracts

Note that these inherit from TournamentStyle and Round classes. They may strengthen the invariants and post-conditions, and weaken the pre-conditions.

Sample Problem

9.6.4 - Lessons Learned