Re: Use of default methods in interfaces

2020-05-08 Thread Jacob Barrett
> On May 8, 2020, at 1:11 PM, Kirk Lund wrote: > > I want to avoid having Java Interfaces in which every method (or even many > methods) has a default empty implementation. I think that's ok for callback > interfaces like CacheListener, but it's horrible for interfaces like Cache, > Region, Int

Re: Use of default methods in interfaces

2020-05-08 Thread Kirk Lund
I want to avoid having Java Interfaces in which every method (or even many methods) has a default empty implementation. I think that's ok for callback interfaces like CacheListener, but it's horrible for interfaces like Cache, Region, InternalCache, InternalRegion. I don't think these non-callback

Re: Use of default methods in interfaces

2020-05-08 Thread John Blum
> *appropriate when the new method can be defined in terms of other existing methods in the interface* This is what it means when a method employs the "template" design pattern. Correction to my (earlier) example: @FunctionalInterace interface Sorter { default Object[] sort(Object... array

Re: Use of default methods in interfaces

2020-05-08 Thread Owen Nichols
Default interface methods are especially appropriate when the new method can be defined in terms of other existing methods in the interface. For examples, when Collections added isEmpty(), it is basically just a shorthand for length()==0 [but certain subclasses might still be able to provide a

Re: Use of default methods in interfaces

2020-05-08 Thread John Blum
Another way to think about this is: 1. First, default methods are not inherently bad. They are useful in many situations and can be "overridden" on implementing classes, if necessary. 2. A default method should be provided when the operation is not strictly required or if the implementation (proce

Re: Use of default methods in interfaces

2020-05-08 Thread Jacob Barrett
As a general rule default implementations on an interface should only used when absolutely necessary because all the implementations are out of your control. For example, the collection interfaces in the JDK all gained new APIs but Java doesn’t implement every instance of them so a default is ne

Use of default methods in interfaces

2020-05-08 Thread Kirk Lund
I believe some of the Geode community has already decided that we shouldn't overuse default methods in interfaces. Dan and others were the ones who decided this and thus I can't really explain to folks in PRs why it's bad to overuse default methods. Could some of the folks with strong understanding