12 ms·
Pattern 1: Reasonable Pattern 2: Yes absolutely Pattern 3: Seems a bit inefficient, allocating memory when a simple if statement would avoid calling the metho
by AndrewSChapman 8y ago
Pattern 1: Reasonable
Pattern 2: Yes absolutely
Pattern 3: Seems a bit inefficient, allocating memory when a simple if statement would avoid calling the method at all.
Pattern 4: Would prefer
if (foo && bar) {
return true;
}
return baz;
Than the proposed solution which is harder to read.
Pattern 5: Just no! The repository getRecord method should have no care about coping strategies, which may change depending on the calling context. It should instead throw an RecordNotFoundException. You could also use success and error callbacks in the method signature.
- RodgerTheGreat 8y agoRegarding pattern 3, I think the most correct way to do what the author proposes is to use Collections.EmptyList(). You get an immutable empty list, which by virtue of being immutable need only be allocated once. [1] https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#emptyList() https://docs.oracle.com/javase/7/docs/api/java/util/Collecti...