0

我这里有一个设计问题。我有一个三门课。

- 父亲

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "Persona", schema = "dbo", catalog = "cxc")
Class Person

儿童的

Class User extends Person
Class Customer extends Person

我怀疑这种设计是否适合我的应用程序,因为客户可以访问该应用程序以查看遗产账户并付款。

而且我不知道如果客户不能同时成为用户并保持数据的完整性(因为在现实生活中只有一个人。)

提前致谢

4

4 回答 4

0

Well in Java only single inheritance is allowed.

About design what I would do is:

class User extends Person

and then depending how much Customer is different from User you can skip the Customer class and add additional property of user type in the User class. It can be for example an enum:

enum UserType {
  Customer,
  User,
  Boss,
  // etc...
}

However if there is big business logic behind the Customer and it must be clear difference between users and customers then there is nothing wrong with you design.

于 2013-06-21T19:53:38.423 回答
0

您只能从 Java 中的一个类进行扩展。但是,您可以实现许多接口。这意味着在您的设计中,用户和客户不能相同。

于 2013-06-21T18:40:17.237 回答
0

根据您的描述:de customer can acces to the aplicacation to view the estate acount, and make payments。在我看来,view the estate acountmake payments是客户拥有的特权,而客户本身就是一种角色。

我不确定你为什么要首先将其建模为客户用户,也许应用程序的一些背景会在这里有所帮助。

于 2013-06-24T05:53:33.377 回答
0

也许 Customer 应该是一个接口,而 User 可以实现 Customer。这将允许您让用户表现得像用户和客户(如果我理解正确,这就是您想要的),如果您想仅限于客户部分,只需通过它的接口引用对象,如下所示:

Customer customer = (Customer)/* the user object. */

这意味着 User 的类定义如下所示:

class User extends Person implements Customer {
于 2013-06-21T18:55:49.300 回答