How to Implement Observer Pattern Using SpringBoot Events
Build an Event Driven Architecture in Java through the introduction and understanding of the Observer Pattern
Have you ever worked on a code base that was so tightly coupled it would make SOLID’s cultists want to nuke the whole thing ? Chances are it all started from poor design choices, lack of planing and/or knowledge and horrible coding habits. Fortunately, programming has come a long way since its debuts in the 50’s with FORTRAN and COBOL and many of our peers have had to deal with their shares of spaghetti code and anti-patterns.
The goal of this article is to give you a quick understanding of the Observer Pattern, its benefits and how to implement it in a SpringBoot application to avoid refactoring nightmares.
The exemple project is built using gradle. For convenience, I will be using flapdoodle as an embedded MongoDb instance as well as lombok to generate getters, setters and builders.
You can find the full code on my github here.
- Design Patterns
- What is the Observer Pattern
- Implementation with SpringBoot events
- Conclusion
- Resources