Re: Cayenne 5.0 - getting rid of legacy

Michael Gentry <[email protected]> Tue, 5 Jul 2022 12:55:49 -0400
Newsgroups gmane.comp.java.cayenne.devel
Message-ID <CAOy5kzM5NfbQTePjgBbkUVUhJSAU7TKH=wMGoj_u60Zr8XxiOA@mail.gmail.com>
On Tue, Jul 5, 2022 at 11:46 AM Andrus Adamchik <[email protected]> wrote:

> Now that "default" implementations of interface methods are possible...
>

This sounds more interesting to me. I'm assuming you mean a separate
interface per callback? Something like PostAddLifecyleCallback? You
wouldn't need a default method implementation in that case. If you
implement the interface, you should implement the method. It'll also be
easier for Cayenne to test if the object implements a given lifecycle
interface. If you group them all into a single LifecycleCallbacks
interface, though, then yeah, you'd want default methods and call them
blindly (they would either do nothing -- the default -- or run the object's
lifecycle code).

One possible advantage of annotations is you could include
several @PostAdd-annotated methods, but then you'd potentially have calling
order issues. When we did post-adds, we'd put all the changes in one method
or have that one method call smaller ones in-order. I think I'd prefer the
certainty of a single method (via interface) than random annotation
orderings. Of course, can always throw a runtime error if more than one
method has the same annotation, but I think not having that error at
runtime is a better approach.