O'Reilly logo

Program Development in Java: Abstraction, Specification, and Object-Oriented Design by John Guttag, Barbara Liskov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4 Exceptions

A procedural abstraction is a mapping from arguments to results, with possible modification of some of the arguments. The arguments are members of the domain of the procedure, and the results are members of its range.

A procedure often makes sense only for arguments in a subset of its domain. For example, a procedure that computes the factorial makes sense only if its argument is positive. As another example, the search procedure can return the index of the element only if the element appears in the array.

One way of coping with such a situation is to use partial procedures, as discussed in Chapter 3. For example, we might define gcd only when its arguments are positive:

   public static int gcd (int n, int d)      // REQUIRES: n, d > 0 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required