Preface
Recently, I was working on a project. I talked about it from the customer, requirement analysis, system design, coding, and all-inclusive. The first time I did this,
Depressed, it's not a few days before the delivery, and there are still some unclear ideas, so I will post my thoughts and let you bloger make bricks
Requirement
Here we only write out the relevant part, that is, the user processing part. As required, the system will have five types of users. The three representative descriptions are listed as follows:
1. Instructor user (Teacher): When registering, you can register as a Teacher as an independent identity, or you can choose to associate with a School)
2. School user (SchoolUser): two departments will be generated during registration. One user and the other is a school, and the user will exist as the school administrator. The school information can be used by teachers.
User Selection
3. Expert user (Expert): cannot be directly registered. It must be added by the Administrator in the background
Design
The following describes my ideas based on the entity, data layer, data operation layer, and web layer.
1. entity Layer Design
The entity layer includes user interfaces and other related objects. To facilitate code writing, use fields
No more attributes
Public abstract IUser
{
Public string Username;
Public string Password;
}
Public class Teacher: IUser
{
Public int SchoolID;
}
Public class Expert: IUser
{
// No new attributes
}
Public class SchoolUser: IUser
{
Public School MySchool;
}
Public class School
{
Public string SchoolName;
Public int AreaID;
}
The relationships between entities are shown in the following UML diagram (the first time you draw UML, you don't know if you can understand it). The entity is replaced by an interface and the code is replaced by an abstract class. The meaning is the same.
2. Data Layer
Write the CRUD method for each object separately.
3. Data operation layer
Example of registering a user:
Public class Users
{
Public static void Register (IUser user, UserType userType) // user type Enumeration
{
// Write the judgment logic here, which is also the worst place I think
Switch (userType)
{
// Call the corresponding methods at the data layer here to complete registration tasks for various types of users.
}
}
}
4. web layer call
Take registered school users as an Example
School school = new School ()
// The school initialization code is omitted, the same below
SchoolUser user = new SchoolUser ();
....
User. School = school;
Users. Register (user, UserType. SchoolUser );
I started to shoot bricks ......