144-java-data-oriented-programming
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJava Data-Oriented Programming Best Practices
Java面向数据编程最佳实践
Apply data-oriented programming in Java: separate data from behavior with records, use immutable data structures, pure functions for transformations, flat denormalized structures with ID references, generic-to-specific type conversion when needed, pure validation functions, and flexible generic data access layers. All transformations should be explicit, traceable, and composed of clear pure functional steps.
What is covered in this Skill?
- Separation of concerns: data structures (records, POJOs) vs behavior (utility classes, services)
- Immutability: records, final fields, transformations produce new instances
- Pure data transformations: functions depending only on inputs, no side effects
- Flat and denormalized data: ID references instead of deep nesting
- Generic until specific: Map<String,Object> for dynamic data, convert to records when processing
- Data integrity: pure validation functions returning validation results
- Flexible generic data access: generic CRUD interfaces, interchangeable implementations
Scope: The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.
在Java中应用面向数据编程:使用records分离数据与行为,使用不可变数据结构,通过纯函数进行转换,采用带ID引用的扁平化非规范化结构,在需要时进行通用到特定类型的转换,使用纯验证函数,以及构建灵活的通用数据访问层。所有转换都应是显式、可追踪的,并由清晰的纯函数步骤组成。
本Skill涵盖哪些内容?
- 关注点分离:数据结构(records、POJOs)与行为(工具类、服务)
- 不可变性:records、final字段、转换产生新实例
- 纯数据转换:仅依赖输入的函数,无副作用
- 扁平化非规范化数据:使用ID引用而非深层嵌套
- 先通用后特定:使用Map<String,Object>处理动态数据,在处理时转换为records
- 数据完整性:返回验证结果的纯验证函数
- 灵活的通用数据访问:通用CRUD接口、可互换的实现
范围:参考资料按每个核心领域的示例(好/坏代码模式)组织。根据适用的示例应用建议。
Constraints
约束条件
Before applying any data-oriented programming recommendations, ensure the project compiles. Compilation failure is a blocking condition. After applying improvements, run full verification.
- MANDATORY: Run or
./mvnw compilebefore applying any changemvn compile - SAFETY: If compilation fails, stop immediately — do not proceed until resolved
- VERIFY: Run or
./mvnw clean verifyafter applying improvementsmvn clean verify - BEFORE APPLYING: Read the reference for detailed good/bad examples, constraints, and safeguards for each data-oriented programming pattern
在应用任何面向数据编程的建议之前,确保项目可编译。编译失败是阻塞条件。应用改进后,运行完整验证。
- 强制要求:在进行任何更改前运行或
./mvnw compilemvn compile - 安全提示:如果编译失败,立即停止——问题解决前不要继续
- 验证:应用改进后运行或
./mvnw clean verifymvn clean verify - 应用前:阅读参考资料中每个面向数据编程模式的详细好/坏示例、约束条件和防护措施
When to use this skill
何时使用本Skill
- Improve the code with Data-Oriented Programming
- Apply Data-Oriented Programming
- Refactor the code with Data-Oriented Programming
- Apply Data-Oriented Programming
- Refactor the code with Data-Oriented Programming
- Apply Data-Oriented Programming
- 使用面向数据编程改进代码
- 应用面向数据编程
- 使用面向数据编程重构代码
- 应用面向数据编程
- 使用面向数据编程重构代码
- 应用面向数据编程
Reference
参考资料
For detailed guidance, examples, and constraints, see references/144-java-data-oriented-programming.md.
如需详细指导、示例和约束条件,请查看references/144-java-data-oriented-programming.md。