我在质疑我设计 JavaBeans 的方式。例如,假设我有以下内容:
Employee - basic employee information:
private String employee_id;
private String first_name;
private String last_name;
private String phone;
private String deptNo;
etc..
WorkflowPlayer - details about an employee in a system workflow:
private String workflow_instance_id;
private String employee_id;
private String role_class_id;
private String role_required;
private Employee employee;
private RoleClass roleClass;
RoleClass - details of a type of role (Approver, SecurityReviewer, Originator, Instructor, Manager, etc..)
private String role_class_id;
private String name;
private String label;
private String description;
这三个模型也直接对应于数据库表(Employee 对我来说是一个只读视图,如果这很重要)
然后在我看来,我会做类似的事情
workflow_player.employee.first_name
workflow_player.roleClass.label
将 Employee 设为实例变量是否可以接受?或者我应该改为使用 Employee 扩展 WorkflowPlayer 然后做
workflow_player.first_name
这对员工有意义,但对角色类没有意义。
workflow_player.description
//不!
我只想使用一致的 [正确] 模式