"Three-layer structure" is "appearance layer", "business logic layer", "database layer"
Assume that a message board is made in such a structure, then it should be:
# 留言 板 page The appearance code is stored in the .aspx file.
# When the user clicks on the submission button on the page, first pass the text information to a LeaveWord class object.
(Definition of LeaveWord class is packaged to "Business Logic")
# After letting this object execute post () to send message information to the database
With a simple code is:
// -------------------------------------- // In the appearance layer, when the user Click to send the button later ~ / / -------------------------------------- Private void post_serverclick Object sender, Eventargs e) {LeaveWord LWORD = New LeaveWord (); lword.content = content.value; lword.post ();
// -------------------------------------- // In the business logic layer, definition LeaveWord Class / / ---------------------------------------- Public Class Leaveword {public string CONTENT;
Public void post () {new lworddata (). pos (this.content);}}
// -------------------------------------- // Database layer, define the transmission method // ---------------------------------------- Public Class LwordData {Public Void Post String content) {// Open the database, insert content into the table}}
In this way, the appearance layer does not have to worry about the database operation ...
It is basically correct. But the data layer is only the operation of the database, should not have any relationship with the business, you can refer to SQLHELPER.CS reminder, the system "layer" is a logical partition of the code, not certain three floors Suppose your system is very simple, just a page, that layer can be, if the system is complicated, it may be n-layer. The difference is not too late, the core is the outer layer absolutely not involving any data processing, his task is setting Interface, acquisition data, output data service layer is most important, all data processing here, how to use external-level data processing service database layers generally recommend calling stored procedures, return data sets or other required data;. Net An example is very good, learn more. One principle: The upper layer is unasounced in the upper layer to the lower layer, the performance layer only calls the logic layer, the performance layer is mainly transmitted to the logic layer of the page, and puts the logic layer from the logic layer The resulting data is displayed on the page. The logic layer is responsible for the transfer of data processing to the data layer and putting the data layer from the data layer is only responsible for the operation of the data.