开发者

Multiple user types - inheritence or composition?

I have two "types" of Accounts in my site, with VERY different functionality, and a few different fields between them. These two types, however, share the same table of "basic account" fields.

Is it better, in this case to utilize an inheritance design, where User and Company are simply children of Account, or is it better to use a composition design, where an Account can have either a "user" or a "company" (each with their own functionality) object in it?

Note: the Account table contains the primary id that connects all the types together, and therefore is the way I will actually derive each user or company.

ALSO

I get that this is a fairly subjective question, but I know that there are common practices out there. It makes sense that there should be ideas on when it's ri开发者_StackOverflow中文版ght to do one and right to do another - therefore a right and wrong answer.


If "User" and "Company" are kind of "Account" (like UserAccount and CompanyAccount), then use inheritance.

If, on the other hand, User and Company are distinct entities that happen to have an Account, then use composition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜