Data-oriented programming (DOP) in Java focuses on modeling data as immutable data using records and sealed types, separating it from domain logic. Brian Goetz's four principles are covered: model data accurately, keep data immutable, validate at the boundary, and make illegal states unrepresentable. Practical examples show how sealed interfaces with record implementations replace error-prone patterns like nullable returns or flag-based result types. Pattern matching on sealed types enables ad-hoc polymorphism for operations like evaluation, differentiation, and cost estimation on expression trees—replacing the verbose visitor pattern. DOP and OOP are complementary: OOP excels at defining boundaries in large systems, while DOP suits simpler services processing plain, ad-hoc data.
Sort: