java类设计问题?
天蓬老师
天蓬老师 2017-04-18 10:12:29
0
4
304

我在用ssh写一个基本功能论坛,但是在设计实体类的时候有些迷惑,就是用户的实体类要怎么设计呢,我希望有超级管理员,版主及普通会员,超级管理员和版主会比普通用户多出许多类方法,并且不同角色的成员变量可能也会有许多不同,请问我是应该用一个类表示所有用户还是用继承或者接口什么的来实现我希望的功能呢,麻烦大家指点一下,谢谢

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(4)
黄舟

The design idea has gone astray. You cannot think of placing permissions in the user class. Users are users, and permissions are permissions. This must be distinguished.

用户类仅存储用户的基本信息,如用户名、登录名、姓名、昵称等等,如果你想要不同用户拥有不同的权限去控制你的论坛功能,那么就需要额外的权限角色管理,定义好角色The permissions owned by

, and then assign the role to the user.

🎜This is the correct idea of ​​permission control management. 🎜
左手右手慢动作

This is not a problem related to classes, but a problem of permissions and role management. You only have one user class, some users can click to delete, and some users cannot.
A framework for permission control

左手右手慢动作

It should be implemented using inheritance. In terms of permissions, super administrators > moderators > ordinary members > ordinary users. And from a functional point of view, the former will include all the functions of the latter in turn, that is, only ordinary users have. , the other three roles will also exist, so the inheritance structure is the same as the order of permissions.
And one of the benefits of using inheritance is that if you use an ORM framework (such as MyBatis), all database interactions for ordinary users apply to the latter.

黄舟

Personally, I think it’s better to have a single user class, as all functions can be called inside the program. Determine user permissions before calling to distinguish user operations with different permissions

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template