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
interfaces should have any default empty implementations.

On Fri, May 8, 2020 at 11:32 AM John Blum <jb...@pivotal.io> wrote:

> 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 (procedure/algorithm) is rather simple
> (e.g. following the template pattern), for example...
>
> @FunctionalInterace {
> interface Sorter {
>
>     default  Object[] sort(Object... array) {
>         return convert(Arrays.asList(array)).toArray();
>     }
>
>     <T extends Iterable<?>> T convert(T collection);
>
> }
>
> 3. If the interface footprint is small (as it should be) then it is
> possible to use in *Lambda* expressions (and *Method References*), as
> proper @FunctionalInterface as shown above, which is very useful when
> composing *Streams*, etc.
>
> Food for thought.
>
> -j
>
>
> On Fri, May 8, 2020 at 10:17 AM Jacob Barrett <jbarr...@pivotal.io> wrote:
>
> > 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
> > necessary for forward progress. However, if you own all instances you
> > should not need to use default. So in this particular PR the use of
> default
> > in the InternalCache in my opinion is wrong. We should control all
> internal
> > interfaces and therefor can update them all with the correct
> > implementation.
> >
> > -Jake
> >
> > > On May 8, 2020, at 9:49 AM, Kirk Lund <kl...@apache.org> wrote:
> > >
> > > 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 of why we should avoid making every method default empty
> > > please speak up here and/or in
> https://github.com/apache/geode/pull/5014
> > ?
> > >
> > > My understanding is that default implementations should only be
> provided
> > in
> > > interfaces when it's important to do so for facilitating some sort of
> > > deprecation and replacing a deprecated method.
> > >
> > > Thanks,
> > > Kirk
> >
> >
>
> --
> -John
> Spring Data Team
>

Reply via email to