Three tier architecture of software & principles to be followed

Three tier architecture

Layered mode
Layered mode is the most common architecture mode
The layered pattern is the foundation of many architectural patterns

layered

Separate the components of the solution into different layers
Maintain cohesion between components in the same layer
Loose coupling between layers

Why do I need a layered model?

1: Team development, change to management
The three-tier architecture makes cooperative development possible. Because each layer is independent, a group only needs to be responsible for blocks
2: Easy to find and modify bug s
The upper layer depends on the lower layer. If there is no problem in testing the lower layer, the problem can only appear in this layer, which is convenient for finding and modifying bug s, reflecting the idea of "high cohesion and low coupling"

What principles should be followed when implementing layering?

The upper layer depends on its lower layer, and the dependency relationship does not cross layers
The presentation layer cannot directly access the data access layer
The result of the upper layer calling the lower layer depends on the implementation of the lower layer
The next layer cannot call the previous layer
The next layer does not depend on the previous layer
The change of the upper layer will not affect the next layer
Changes in the lower layer will affect the results obtained in the upper layer
The concept of the next layer cannot appear in the upper layer
Clear division of labor and performing their respective duties

What are the advantages of layered development?

1: Maintainability: if the demand changes, just adjust the implementation of a certain layer accordingly;
2: Layered management: conducive to division of labor
3: Scalability: only one layer needs to be modified to add functions

Characteristics of layered development:

The lower level does not know the existence of the upper level
Complete only its own functions
Don't care how the results are used
Each layer only knows the existence of its lower layer, ignoring the existence of other layers
Only care about the achievement of results
Do not care about the implementation process of the results
JSTL usually cooperates with EL expressions to realize the coding of JSP pages

Entity classes run through three layers, and can be called in all three layers

Layered Code: Here I use the first method

package com.zking.IUserDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.zking.uitl.DBHelp;
/**
 * dao Methods add, delete, modify and check
 * 
 * @author JIE
 *
 * @date 2022 April 6, 2014 4:10:42 PM
 */
public class UserDao implements UserDaoimpl{
	Connection con=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	/**
	 * User login authentication
	 * @param name user name
	 * @param pwd User password
	 * @return Success or failure
	 */
	public boolean login(String name,String pwd) {
		boolean f=false;
		try {
			con=DBHelp.getcon();
			String sql="select * from tb_web where sname=? and spwd=?";

			PreparedStatement ps=con.prepareStatement(sql);
			ps.setString(1,name);
			ps.setString(2,pwd);
			
			ResultSet rs=ps.executeQuery();
			if(rs.next()){
				f=true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBHelp.myClose(con, ps, rs);
		}
		
		return f;
	}
 
}

package com.zking.IUserDao;


public interface UserDaoimpl {
	/**
	 * User login authentication
	 * @param name user name
	 * @param pwd User password
	 * @return Success or failure
	 */
	public boolean login(String name,String pwd);
	
}

package com.zking.biz;

/**
 * User business logic layer
 * 
 * @author JIE
 *
 * @date 2022 5:59:12 PM, April 11
 */
public interface Userbiz {
	/**
	 * User login authentication
	 * @param name user name
	 * @param pwd User password
	 * @return Success or failure
	 */
	public boolean login(String name,String pwd);
	
}

package com.zking.biz;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.zking.IUserDao.UserDao;
import com.zking.IUserDao.UserDaoimpl;
import com.zking.uitl.DBHelp;

public class Userbiziml implements Userbiz{
	
	UserDaoimpl iud=new UserDao();
	/**
	 * User login authentication
	 * @param name user name
	 * @param pwd User password
	 * @return Success or failure
	 */
	public boolean login(String name,String pwd) {
		
		
		return iud.login(name, pwd);
	}
}


Tags: Java Oracle

Posted by davo666 on Tue, 12 Apr 2022 08:42:59 +0300