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 Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M} of object Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle O} may invoke methods of following kinds of objects:
    • Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle O} itself
    • Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M} 's parameters
    • Any objects created/instantiated within Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M}
    • Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle O} 's direct component objects
    • Global variables, accesible by Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle O} , in the scope of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle M} .


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.