It has been more than three weeks since the reconstruction of the data center. from the beginning to the end, we have no idea how to start.
Such as a reborn. Compared with two weeks ago, it is much clearer now, and the mood is quite good.
Let's take a look at the overall architecture diagram of this reconstruction:
In the previous blog, the three layers (ui, BLL, Dal, and entity) are hidden.
This blog focuses on the improvements I have made on the basis of Layer 3, that is, the legendary Layer 7.
1. facade layer (appearance layer)
Definition: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the subsystem easier to use.
Personal Understanding: The appearance mode is like a directory, which integrates all the methods into this layer (like an interface) and is a node, what the U layer needs is called directly from the appearance layer, which reduces the coupling between the U layer and the B layer, facilitating the call of methods.
The data center reconstruction login form is used as an example to share the Code:
<Span style = "font-family: kaiti_gb2312; font-size: 18px; "> ''' <summary> ''' verify logon ''' </Summary> ''' <Param name =" enuser "> </param> ''' <returns> ture or false </returns> ''' <remarks> </remarks> Public Function select_faced (enuser as chargeentity. charget_usersentity) as Boolean dim selectfaced as new chargemanagerbll 'instantiate layer B dim dT as Boolean 'defines dT as set type dt = selectfaced. selectuserbll (enuser) 'calls the layer B function return DT end function </span>
2. Abstract Factory + reflection + configuration file-implement Database Access
Abstract Factory: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.
Below is a method of my Abstract Factory
<Span style = "font-family: kaiti_gb2312; font-size: 18px;"> imports system. reflection 'introduce the reflection imports system. configuration 'reference Assembly imports chargeidal' reference interface public class charget_usersfactory private shared readonly assemblyname as string = "chargedal" 'declares the Assembly name private shared readonly dB as string = configurationmanager. appsettings ("DB ") ''' <summary> ''' User Logon ''' </Summary> ''' <returns> ture or false </returns> ''' <remarks> </ remarks> Public Function selectusers () as charget_usersidal dim iselect as chargeidal. charget_usersidal dim classname as string = "chargedal" + ". "+ dB +" charget_usersdal "'concatenates strings to achieve database access iselect = ctype (assembly. load (assemblyname ). createinstance (classname), charget_usersidal) return iselect end function </span>
Configuration File: App. config, which exists on the UI Layer.
<Span style = "font-family: kaiti_gb2312; font-size: 18px;"> 1. General Format: <configuration> 2 <configsections> // The Declaration area of the configuration section, contains the configuration section and namespace Declaration 3 <section> // configuration section declaration 4 <sectiongroup> // defines configuration section group 5 <section> // configuration section group configuration section declaration 6 <appsettings> // predefined configuration section 7 <custom element for configuration section> // configuration section setting area </span>
My configuration file:
<span style="font-family:KaiTi_GB2312;font-size:18px;">?xml version="1.0" encoding="utf-8" ?><configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <appSettings> <add key="DB" value="Sqlserver"/> <add key ="sqlConnect" value ="Data source=.; Database =ChargeSystem; User ID = sa;Password = 123456 "/> </appSettings> </configuration></span>
Note: To write the configuration file, you must reference system. configuration. Note: When database is included in the concatenation string in the factory, change the class name corresponding to layer D.
Is: DB name + class name in the configuration file. Alternatively, you can remove the DB from the previous factory without changing the Class Name of the d layer.
Reflection: Provides encapsulated assembly, module, and type objects. I have used this in the abstract factory.
3. Interface: layer B calls the method of layer D through the interface and does not directly deal with the database. This reduces the coupling between layer B and layer D and ensures security.
Some of my interfaces:
<Span style = "font-family: kaiti_gb2312; font-size: 18px;"> mports chargeentity public interface charget_usersidal 'defines the login interface function selectusers (enuser as chargeentity. charget_usersentity) as List (of chargeentity. charget_usersentity) 'defines the function changepwd_dal (enuser as chargeentity. charget_usersentity) as Boolean 'defines the function adduser_dal (enuser as chargeentity. charget_usersentity) as integer 'defines the query user interface function finduser_dal (enuser as chargeentity. charget_usersentity) as List (of chargeentity. charget_usersentity) 'defines the function deleteuser_dal (enuser as chargeentity. charget_usersentity) as integer End Interface </span>
Personal eyes: The appearance layer and interface layer are actually the same, reducing the coupling of each layer and making the call method more convenient. Create a connection through an abstract factory
Interface. layer I defines the interface and layer D implements the interface. This is also called interface-oriented programming. Database Access is realized through abstract factory + reflection + configuration file
Q: It makes database replacement more flexible and convenient in the future. Layering is actually like building a house. After the skeleton is set up (layering), the rest is slowly
It's just a pile of bricks.
IDC reconstruction Abstract Factory + reflection + configuration file