Emil Smęt
Emil Smęt

Reputation: 909

Class/entities desing. User class and it's subclasses

I would like to know what's your opinion on how to design sth like this.

I have a few kinds of users let's say they are called A,B,C. They all can be subclasses of class User. (They all will have different kind's of permissions that will allow them to read / write / enter certain pages of application.)

How should I design those calasses (A, B, C with/without superclass User) and tables in DB so they will work well in my application.

I'm writting in JEE with JSF. I'm reading about design patterns, but I don't know how to implement them with given DB tables.

(e.g. How i will map the relationship beetween a abstract class User and it's subclasses in DB)

I'm using plain JPA.

Upvotes: 1

Views: 48

Answers (1)

kiwiron
kiwiron

Reputation: 1705

Firstly, are you sure you have the correct overall class design? In many situations, a user may be a "User" today, but may later be promoted to be an "Administrator". This indicates that the user is playing a role, which is time constrained. If that is the case, inheritance is not the correct modelling technique. Peter Coad is the guru in this area - try Googling on his name.

Mapping object graphs to relational database tables is well-trodden territory. There are three main methods - one table per class hierarchy; one table per concrete class and one table per class (both abstract and concrete). No method is perfect - they all have tradeoffs. It is quite common for multiple mapping strategies to be used in the same database. Again, Google is your friend.

Upvotes: 1

Related Questions