General Development Theory

Only the client-server is discussed here.

1.
General level 0: Client: The client can be: web, android, ios and so on. The client is mainly responsible for interacting with the user, interacting with the server, and so on.
1: Routing layer: mainly responsible for distributing requests, parameter verification, calling services, template rendering, etc.
2: Service layer: mainly composed of domain models, performing specific request services
3: Bottom layer: performing machine operations, such as persistent data, Access to third-party interfaces, etc.

Service
layer The service layer is mainly composed of domain objects. The specific structure of the domain model depends on the type of request, including instantaneous and non-instantaneous requests.
Transient requests:
Transient requests are converted to stateless processing methods as much as possible, that is, after the request is completed, no state is preserved in the program. All data is in parameters and the final state is saved to the database and file system. Services, etc. are mapped into a series of sql and io operations. Designing such a service requires only a grouping of similar functions. Such methods are basically not overridden by inheritance, so they can be designed as static methods. The object-oriented approach is of little use here.
The final model of the domain is in the database, not the program. Such programs are just methods for database and IO operations. Therefore, the design and maintenance of the database and file system are the core parts.
E.g:
public class UserService {
	private static Logger log = LoggerFactory.getLogger(UserService.class);
	public static User signin(SigninParam param) {
		try(Connection con = MysqlPool.get()) {
			User user = Sqlx.SelectOne(con , "select id,name,group from users where username=:username and password=:password" , param ,User.class);
			return user;
		} catch (SQLException e) {
			log.error("UserService.signin sql error" ,e);
			throw new CodeException(Codes.NO_SUCH_USER);
		}
		
	}
}
public class SigninParam {
	public String username;
	public String password;
}

Choice of ORM: I tend to put sql to the tool that maps objects, ORM should be as simple as possible. It is best to write sql directly, complex sql needs to be optimized.
The code should be kept as simple as possible and don't reference third-party frameworks if not necessary.
Non-instantaneous request:
Only when objects exist in memory for a long time, we need to use object-oriented methods, and we need to use programs to model, maintain various states, process various events, and so on.
An example: online classes. The online classroom server-side programming model should exist at least for the duration of the class. Various states of the classroom need to be saved in real time, such as the state of the classroom, the connection of the users used, the real-time data of the classroom, etc. These data should exist in the memory, that is, my model is not instantaneous, but exists for a long time. .
What we have to do is maintain the life cycle of the class model, create, initialize, handle events, destroy objects, etc.
public class Course extends Room{
	private List<Client> clients;
	private Client teacher;
	private int courseId;
	
	public Course(int courseId) {
		this.courseId= courseId;
	}
	@Override
	public void handleMessage(Message message) {
		switch (message.cmd) {
		case start:
			break;
		default:
			break;
		}
	}
	public void close(){
		
	}
}


Division of
modules: The division of modules should be based on the root object. The root object can exist independently and does not depend on other objects. When designing the domain model, the user should not be the core, but the domain function itself should be the core, and the user is only the user.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326371986&siteId=291194637