在DAO中反映继承关系的最有效方法? [英] Most effective way to reflect inheritance relationship in DAOs?

查看:85
本文介绍了在DAO中反映继承关系的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MVC结构和业务对象 / DAO 体系结构。对于任何普通的业务对象,CRUD功能都非常简单。但是处理诸如客户就是用户之类的父子关系的最佳方法是什么?

Working on a business application using MVC structure and a Business Object / DAO architecture. For any normal business object, the CRUD functions are fairly straightforward. But what's the best way to handle a parent-child relationship like "Customer is a User"?

我知道涉及以下类:

User, UserDAO, Customer, CustomerDAO

Customer 类可以很好地从 User 继承,但是您如何最好地在DAO CRUD函数?

The Customer class can inherit from the User just fine, but how do you best reflect this in the DAO CRUD functions?

推荐答案

马丁·福勒(Martin Fowler)已记录了一些可能会帮助您的对象关系结构模式

Martin Fowler has documented a few Object-Relational Structural Patterns that might help:

1)单表继承:将类的继承层次结构表示为一个表,其中包含各个类的所有字段的列。

1) Single Table Inheritance: Represents an inheritance hierarchy of classes as a single table that has columns for all the fields of the various classes.

例如 Employee Customer 都从 User 继承并存储在用户表中,具有确定特定记录代表的用户类型的列。

e.g. Employee and Customer both inherit from User and are both stored in the User table, with a column that determines what type of user a particular record represents.

2)类表继承:表示以下项的继承层次结构:每个班级都有一张桌子。

2) Class Table Inheritance: Represents an inheritance hierarchy of classes with one table for each class.

例如 Employee Customer 均从 User 继承,表来代表这一点。用户表存储所有用户共有的属性。 Employee表具有一个指向User表的指针,并且仅存储与Employees相关的属性。客户表也是如此。

e.g. Employee and Customer both inherit from User and there are three tables to represent this. The User table stores the properties common to all users. The Employee table has a pointer to the User table and only stores the properties relevant to Employees. The same is true of the Customer table.

3)混凝土表继承:表示以下项的继承层次结构:类,在层次结构中每个具体类具有一个表。

3) Concrete Table Inheritance: Represents an inheritance hierarchy of classes with one table per concrete class in the hierarchy.

例如 Employee Customer 都继承自抽象的 User 类,并且有两个表可以代表这一点。客户表和雇员表。每个表存储用户共有的信息,但还存储唯一的属性。

e.g. Employee and Customer both inherit from the abstract User class and there are two tables to represent this. A Customer table and an Employee table. Each table stores information common to users, but also stores unique properties.

这篇关于在DAO中反映继承关系的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆