After getting the first version of #Java samples of #EventSourcing, I asked the community for feedback for my PR
https://github.com/oskardudycz/EventSourcing.JVM/pull/1
I wanted to get harsh but fair feedback to make it idiomatic and, in general, better. I got what I ask for, let me share what I learned 👇😅 1/
Java Optional should be used only as a result, to reduce the confusion around the `void` type. It should not be used as a method input parameter or field. This makes sense, as Java generics are more compile-time templates and are zipped. See more in: https://nipafx.dev/design-java-optional/ /2
I already used sealed interfaces to have a nice pattern matching while rebuilding the state from events. Yet it appeared that they allow full "union types" experience! After that, I went further and created 👇It enables concise and precise modelling /3 https://twitter.com/oskar_at_net/status/1506998215714955268
Spring Boot has a built-in ApplicationEventPublisher ( https://reflectoring.io/spring-boot-application-events-explained/), so there's no need to implement a custom in-memory bus. I had to go full-circle and remove my "great" but totally redundant implementation. Reminder: not forget to learn tools, before going custom /5
Pushing up all the possible exceptions is like being sainter than the pope. If we don't want to handle them in code, then it's better just to make them runtime exceptions and catch them in a generic mechanism. Read more about checked/unchecked split /6 https://baeldung-cn.com/java-checked-unchecked-exceptions
As I'm not a huge fan of annotations/attributes/decorators with conventional-based magic, I decided to do manual Java Beans registrations. I stand by my decision, but I think that I went too far. It's better to compose stateless code rather than outsourcing it to DI /8
I also added Log4J instead of System.out.println. Yup Log4J. Btw. I think that their famous "breach" was more an issue with the enterprises not having a proper dependency upgrade strategy. Everyone can be breached, but we need to be prepared for that as architects. /12
If you reached here, then I hope that this thread will help you learning on my mistakes. Not always we have to do our own. Here's the full, merged sample. Feel free to send a feedback if you want to have it expanded! /14
https://github.com/oskardudycz/EventSourcing.JVM/tree/main/samples/event-sourcing-esdb-simple
Some numbers:
- 143 comments in discussions,
- 47 commits,
- 80 files changed,
- 3,906 lines of code.
That was a long run!
Thanks again for the great reviews and the lesson I got! 😅 15/15 https://twitter.com/oskar_at_net/status/1507830576358830094
You can follow @oskar_at_net.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: