Specification of methods

Specification of methods - Specifications of methods You...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Specifications of methods You know what the first function mini does, because its specification, in the comment preceding it, tells you. You don’t need the function body —which we show you now. You have no idea what the second function does, because its specification has not been given. To understand what it does, you would have to look at its body: Integer.signnum . A specification of a method defines what a call on a method does. The specification should be precise, complete, and as clear as possible. So that you don’t have to look at the method body. In fact, every method should have a specification, and you should never have to look at the method body when writing a call on a method. The method body indicates how a task is carried out. When writing a call on a method, we don’t want to know that, we want to know what the task is. And the spec should tell us. Writing procedure specifications We write method specs as Javadoc comments immediately preceding the method. Javadoc comments begin with /** and end with */ . The next lecture will explain why we use Javadoc comments. Let’s begin discussing specs for procedures. There are two points to make here. /** Set the title to t */ public void setTitle(String title){. ..} 1. The spec mentions every parameter by name, and in a way that explains what that parameter is for. If a
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell.

Page1 / 2

Specification of methods - Specifications of methods You...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online