posted 18 years ago
Its not a shouldn't do thing that assertions not used to validate parameters to a public method. you can use assertions to validate parameters of a public method. But, its a good-to-do kind of thing to use assertion to validate parameters to only private methods. Because, the main purpose of assertion is that you are sure of a condition not going to occur but still to protect those conditions. If and only if the method is private, you can assure that a condition cannot happen because you are only going to use. But if it is a public method exposed to other classes, wrong parameters can be passed by one or the other more obviously. So, it is not good to use assertion to validate parameters to public methods (since a public method can receive wrong arguments more often than a private method).
sorry, I couldnt give an example since it is more of a design issue.