Class Specifications - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Class Specifications

Description:

appears as an arrow within a 'Drawing Canvas' window. ... This object is set to drawing mode, so the arrow is colored green. ... pencil.moveForward ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 11
Provided by: davidd54
Category:

less

Transcript and Presenter's Notes

Title: Class Specifications


1
Class Specifications
2
Class Specification
  • What does the DrawingTool do exactly?
  • Where is it positioned initially?
  • How far does it move forward?
  • How much does it rotate?
  • How to answer the above questions?
  • Ask someone else to tell you
  • Guess
  • Examine the source code
  • Read the documentation

3
Class Specification
  • A way of defining semantics of a class
  • complete and unambiguous definition of meaning
    (at least when done formally)
  • Includes two notions
  • Class invariant what is always true about the
    class
  • Method specification a specification of behavior
    for a method
  • A class specification will have
  • One class invariant
  • A method specification for each method

4
Class Specification
  • A method specification has three clauses
  • precondition (optional)
  • States the condition required for the method to
    execute
  • modifies clause (optional)
  • A list of variables that might be modified by
    this method
  • postcondition
  • States what is true at the conclusion of the
    method

5
Example Class Specification
6
DrawingTool Class Specifications (continued)
Constructor Method public DrawingTool()
postcondition a new
DrawingTool object is created and placed in the
center of the Drawing Canvas
window. (Note that it is possible for one
DrawingTool to cover another.)
This object is set to drawing mode, so the arrow
is colored green. The arrow for
this object is pointing straight up. Update
Methods public void draw()
postcondition This object is set
to drawing mode, so the arrow is colored green.
A 0.5 sec. delay occurs following
this methods execution. public void
dontDraw() postcondition
This object is set to moving mode, so the
arrow is colored red. A 0.5 sec.
delay occurs following this methods execution.
public void turnClockwise()
postcondition This objects
direction of travel is rotated by 90 degrees
clockwise from its previous
(old) direction. A 0.5 sec.
delay occurs following this methods execution.
7
Think of a class specification as a legal
contract for the class.
8
Exercise 1
  • Write a class invariant for TV
  • Write a method specification for
  • turnSetOn
  • raiseVolume1db

9
Exercise 2
  • Given the Vehicle class diagram, construct a
    class specification

10
Given the class specifications for DrawingTool,
explain the behavior of the following program.
public class Director private DrawingTool
pen, pencil public Director() pen
new DrawingTool() pen.moveForward()
pen.moveForward() pencil new
DrawingTool() pencil.dontDraw()
pencil.moveForward() pencil.moveForward()
pen.turnClockwise()
pencil.turnClockWise() pencil.turnClockwise
() pencil.turnClockwise()
pencil.draw() pen.moveForward()
pencil.moveForward()
Write a Comment
User Comments (0)
About PowerShow.com