Perl6 Object Oriented Cookbook (v0.2.1)  
Section 9: Assertions and Invariants  
 
Recipe 9.15: Placing Preconditions on Method Arguments
Last Updated: Sep 8, 2003
Status: Draft
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
5.00 Rating, 1 Vote  

How acceptable is the proposed solution?
  (Login to Vote)
0.00 Rating, 0 Votes  

Problem:  

You want perform validity checking on an argument to your method, for example, to perform bounds checking on the argument. You want the validity check to be part of the method interface, so that it is performed regardless of the method implementation.

Solution:  

Discussion:

(Example: arg = n percent, so assert 0 <= n <= 100)
(I'd probably rather associate multiple preconditions with the method itself, since that's more powerful and would make this obselete?)


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page