From Hexagonal Architectures to Data Oriented Programming
Feb 25, 2024
auto_awesome
Java expert Jose Paumard discusses object-oriented vs data-oriented programming, Java record classes, hexagonal architectures, decoupling and abstractions. They explore sealed interfaces, switch expressions, and data-oriented programming with NoSQL. Also, an interesting conversation about the classic French car, the Citroen 2CV (Duck)
Decoupling in hexagonal architectures emphasizes clean architecture and modular communication.
Data-oriented programming shifts focus to data and validation rules, moving away from complex inheritance systems.
Sealed interfaces facilitate efficient business logic implementation outside data classes, enhancing code maintainability.
Deep dives
Organizing Architecture: Hexagonal vs. Port Adapters
The discussion delves into organizing object-oriented programming akin to hexagonal architecture or port adapters architecture. This involves structuring modules, their communication, and dependencies. Central to this approach is avoiding business code dependence on specific implementation details like database choice. Decoupling principles and module dependencies were highlighted, emphasizing the need for clean architecture.
Data-Oriented Programming Misunderstandings
The conversation explores the shift towards data-oriented programming, advocating for objects to focus solely on data and validation rules. Contrastingly, object-oriented programming emphasizes objects performing tasks themselves, including behaviors. The inherent issue of maintaining complex inheritance systems and the importance of adaptable code in the face of changing features were underscored.
Trade-Offs in Code Maintenance and Design
The dialogue outlines trade-offs in code design and maintenance, emphasizing the impact on bug fixes, feature additions, and feature removals. The balance between quick, dirty code for short-term projects and the implications on long-term code maintenance and feature removal were discussed. The importance of maintaining simplicity for bug fixing and future-proofing code against changing requirements was a focal point.
Introduction to Sealed Interfaces in Java
The podcast delves into the concept of using sealed interfaces in Java to handle business logic more efficiently. The speaker emphasizes that data-oriented programming suggests moving away from putting business logic in objects, which leads to the necessity of finding alternative solutions. By introducing sealed interfaces to mark different types of contracts implemented with records, the need for countless inheritance-based methods is eliminated. Using factory methods with sealed interfaces streamlines the process of dealing with multiple contract types.
Data-Oriented Programming and NoSQL Databases
The episode also explores the application of data-oriented programming in the context of handling data from NoSQL databases. By using sealed interfaces to represent data types derived from database queries, the speaker highlights a shift towards a more type-centric approach rather than traditional inheritance models. The discussion touches on leveraging switch statements and pattern matching in Java for improved code safety and maintainability, especially when dealing with multiple data types. The parallels drawn to functional programming highlight the benefits of immutability and efficient data mapping in data-oriented design.
discussion about Object-oriented programming vs data-oriented programming in Java,
using Java record classes,
hexagonal architectures,
considerations for decoupling and abstractions,
the advantages of polymorphism and transparent persistence,
the pitfalls of inheritance and abstraction,
the importance of naming and cohesion
sealed interfaces and switch expressions to implement business logic outside of data classes,
using sealed types and switch statements,
advantages of better separation of concerns and ease of removing unused code,
data-oriented programming with NoSQL,
the Citroen 2CV (Duck) Car