Hierarchy

A layered structure
1. 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)
If you want to develop a hierarchical structure plus function, only need to add class methods layers can, in line with the development of software
Principles: the principle of opening and closing.
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:
开发过程中代码编写的顺序:
0.添加数据库表
1.添加实体类。
2.添加持久化层接口
3.添加持久化接口实现类
4.添加业务层接口
5.添加业务层接口实现类
6.添加Servlet
7.添加jsp 页面.
二、MVC模式
MVC是一种软件结构开发的一种思想,注意,不是软件开发的设计模式。
软件开发设计有23种(单例,简单工厂,抽象工厂,观察者,桥接…)。
MVC 思想在上个世纪70年代就提出了。SpringMVC ,Struts2…
M: model 数据的业务模型。
C: controller 控制器,对请求进行处理。
V: view 视图,数据的显示或收集。
MVC 的项目结构与分层结构非常接近,只是在把各层的划分进行了细微的更改。
MVC的思想与分层结构的思想是一致的。
优点是:解耦,分工合作,维护扩展。
在开发中,如果是C/S项目,我们用分层结构处理,MVC只能用于B/S结构的项目。

Guess you like

Origin www.cnblogs.com/aknife/p/10988185.html