Web development hierarchical structure and MVC model

1. hierarchy

  The so-called hierarchy. The different function code packaged as such, the same type of packaging functions in one package, also called layer. Features categorized as follows:

Entity classes:

  Encapsulating the data, the data carrier is carried out between the transfer layers, it will transfer the data. For example, student information to be transmitted, the student information package to a Student object, is transmitted to the other classes. If there are a plurality of student objects, the re-packaged into a set for delivery. We put all the classes in a package entities (layers), usually named entity or layer model. How many tables in the database, the program there are that many entity classes. Consistent with the named entity class table name, the name of the entity class attributes consistent with the field names in the table.

  Persistent classes:

  The layer class interacts with the database, that is, data persistence, whenever the code interacts with the database are the class of this layer, named dao of this layer (database access obejct), the layer named classes are: Table name + Dao. Usually the number of tables in the database, there are that many persistent classes.

Business class:

  Traffic class for processing business logic code. Biz or service name of this layer. Class name: Table name + Service.

Jsp page:

  It represents a layer for presenting the data collection or data. Servlet class also belong to the presentation layer, its effect on the reception request from the client, and the request distribution processing, and then in response to the client. Name: Table name + Servlet

Tools:

  In development, there will be a utility class, these tools are usually put a util package. (String processing tools, the tool is connected to the database, the encrypted password tools)

The role of hierarchy:

  If you want to develop a hierarchical structure plus function, only need to add a method like the layers on it, in line with the principles of software development: the principle of opening and closing.

  Open Closed Principle:

Add the code represents the open door is open, change the code of the door is closed.
Defective item hierarchy: Code increased.
Advantages are: to achieve decoupling between class and is conducive to cooperative development is conducive to post-maintenance, expansion.

  Access the relationship between the layers:

    web-> Servlet-> Service-> dao-> Database => dao => Service => Servlet => jsp

  Project structure:

 

    

 

  Sequential write code development process:

0. Add database table
1. Add entity classes.
2. Add the interface persistence layer
3. Add persistent class interface
4. Add the service layer interface
5. Add the business layer interface class
6. Add the Servlet
7. The jsp pages added

 

2.MVC mode

MVC is an idea developed a piece of software architecture, note, not software development design patterns.
There are 23 kinds of software development and design (singleton, simple plant, abstract factory, observer, bridge ...).
MVC thoughts on the 1970s put forward. SpringMVC, Struts2 ...
M: business model model data.
C: controller controller, to process the request.
V: view to display or collect data.
MVC project structure and hierarchy are very close, but in the divided layers were minor changes.

  

 


I thought and thought MVC hierarchy is consistent.
Advantages are: decoupling, division of labor, maintenance expansion.
In development, if it is C / S project, we deal with a hierarchical structure, MVC only for project B / S structure.

Guess you like

Origin www.cnblogs.com/gaojinshun/p/11025351.html