Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: How to handle same sanity checks Date: Sat, 24 Jun 2017 12:06:28 +0200 Lines: 28 Message-ID: References: <87o9tgo0a9.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 13LT4qr0XZ9V49gmAbdrUgwDYzrm3YWxpQUnMuzPbE5yHumpI= Cancel-Lock: sha1:93G2njXnyhwi5ZjhEhp0y9wjpcU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:36711 On 22.06.2017 12:27, Martin Gregorie wrote: > I agree that using such a method would tidy up the calling code, but if I > used this type of method I'd generalise it to something like this: > > private void checkInRange(int n, > int lowLimit, > int highLimit, > String error) > { > String format = "%s: %d is outside range %d - %d"; > if ((n < lowLimit) || (n > highLimit)) > throw new InvalidParameterException( > String.format(format,error, n, lowLimit, highLimit)); > } Premature modularization. That makes only sense if the variability is needed. Since this is a private method (which should be static btw.) I would only do the minimum what is needed. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/