This article graphic details python three-tier architecture this article graphic details python three-tier architecture
A three-tier architecture usually divides the entire business application:
Presentation layer, Business Logic Layer, and Data access layer ).
The purpose of differentiation is to "high cohesion and low coupling.
High cohesion and low coupling are the concepts in software engineering, the criteria for judging the design quality, mainly object-oriented design, mainly to see whether the class cohesion is high, and whether the coupling degree is low.
Cohesion is the closeness of elements in a module. high cohesion is the closeness of elements in a module.
High cohesion refers to a software module that consists of highly correlated code and is responsible for only one task, that is, a single responsibility principle.
Coupling: a measurement of the degree of interconnection between different modules in a software structure (coupling is also called inter-block connection. A measure of the closeness between modules in the software system structure.
The closer the relationship between modules, the stronger the coupling, and the poorer the module independence. the coupling between modules depends on the complexity of inter-module interfaces, the call methods, and the transmitted information .)
For low coupling, the rough understanding is:
A complete system, between modules, try to make it independent.
That is to say, let each module complete a specific sub-function as independently as possible.
The interfaces between modules are as few as possible and as simple as possible.
If the relationship between two modules is complex, it is best to consider further module division first.
This facilitates modification and combination.
Three-tier architecture, such:
#coding:utf8from utility.sql_helper import MySqlHelperclass Admin(object): def init(self): self.helper = MySqlHelper() def Get_One(self,id): sql = "select * from userinfo where id = %s" params = (id,) return self.helper.Get_One(sql, params) def CheckValidate(self,username,password): sql = "select * from userinfo where name=%s and password=%s" params = (username,password,) return self.helper.Get_One(sql, params)
#coding:utf8import MySQLdbimport confclass MySqlHelper(object): def init(self): self.conn_dict = conf.conn_dict def Get_Dict(self,sql,params): conn = MySQLdb.connect(**self.conn_dict) cur = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor) reCount = cur.execute(sql,params) data = cur.fetchall() cur.close() conn.close() return data def Get_One(self,sql,params): conn = MySQLdb.connect(**self.conn_dict) cur = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor) reCount = cur.execute(sql,params) data = cur.fetchone() cur.close() conn.close() return data
#coding:utf8conn_dict = dict( host='127.0.0.1', user='root', passwd='123456', db ='Admin' )
# Coding: utf8from module. admin import Admindef main (): user = raw_input ('username: ') pwd = raw_input ("password:") admin = Admin () result = admin. checkValidate (user, pwd) if not result: print 'user name or password is incorrect 'else: print' to enter the background logon interface 'if name = 'main': main ()
The above is a detailed description of the python three-tier architecture. For more information, see other related articles in the first PHP community!