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
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