This short demo showcases the use of Java sealed interfaces when implementing Typed Error Handling.
It's considered a bad practice to use checked / unchecked exceptions as ways to control the logical flow of an application. Modern Java language features like sealed interfaces and pattern matching provide a way to handle all expected logical branches of an app in a secure, performant and elegant way.
The repo consists of 3 branches:
main
uses exceptions to drive the application logicfeature/refactor-with-sealed-classes
shows a version that uses sealed interfacesfeature/refactor-with-sealed-classes-and-optional
shows a version that uses the now common return type ofOptional<T>
for thefindByEmail
repo method.
- Functional Error Handling with Java
- Intro to VAVR's Either type - a more generic approach of typed error handling