CSCE 431 Lecture 11

From Notes
Jump to navigation Jump to search

« previous | Tuesday, February 18, 2014 | next »


Interfaces and Contracts

Should be determined at design time:

  • specifications of each class interface
  • APIs of subsystems

Object refining:

  • Type signatures (function name, input types, output type)

Access Control

  • Expose as little as possible

Law of Demeter

  • Method of object may invoke methods of following kinds of objects:
    • itself
    • 's parameters
    • Any objects created/instantiated within
    • 's direct component objects
    • Global variables, accesible by , in the scope of .


Object Constraint Language

IBM 1995

Constraints: conditions on all states and transitions between states of a system implementing a given model.


context Tournament inv:
  getNumPlayers() < getMaxNumPlayers()
context Tournament::acceptPlayer(p) pre:
  not self.isPlayerAccepted(p)
context Tournament::acceptPlayer(p) post:
  self.getNumPlayers() = self@pre.getNumPlayers() + 1
context Tournament::removePlayer(p) post:
  getNumPlayers() = @pre.getNumPlayers() - 1


Formal Specification

  • Invariant: predicate that is always true for all instances of a class
  • Pre-condition ("rights"): must be true before an operation is invoked
  • Post-condition ("obligation"): must be true after an operation is invoked.


Constraints can span more than one class.