I have an inner storage layer in my application that processes Foo
objects. During Get operations, the data layer has significant advantages for clustering, but I actually do multiple calculations in about 10% of cases. Here are a few approaches that I have reviewed:
Approach A:
interface FooStorage { Foo getFoo(String name); List<Foo> getFoos(List<String> names); }
Approach B:
interface FooStorage { List<Foo> getFoos(List<String> names); } class StorageUtility { public static <T> T firstOrNull(List<T> data) { ... } }
Approach C:
interface FooStorage { List<Foo> getFoos(String... names); } class StorageUtility { public static <T> T firstOrNull(List<T> data) { ... } }
The disadvantage of approach A is that there is a larger surface that I have to support.
The drawback of approach B is that the consumer creates a list when 90% of the time I donβt need it. The disadvantage of approach C is the overhead of copying a list to an array in 10% of cases.
Is there a canonical correct way to do this?
source share