Agent mode preliminary practice

xiaoxiao2021-03-06  41

I have seen a file on a website saying that there is a very famous Java Forum to write all the management of the background to an agent class, but when the operation arrives, it is only interacted with this class. Later, I checked a dictionary of the design mode, and the definition of the agent mode was as follows: When needed to spend a complex object or creation, the proxy pattern can be used when it is a simple object when it is time-consuming object. If you create an object is a waste of time or a waste of computer resources, Proxy allows the creation process to postpone the time when the actual object is required. Proxy objects typically have the same way as the object it represent, once the object is being tuned, transfer the calling method from proxy to the actual object. Since I just have just entered the road, I will have a similar version of the agent model in the top of the Forum. In order to facilitate, put them with the background of the background in a name space, but I want everyone I know such consequences [Don't do this in the actual work] File name: proxy.csusing system; using system.data.oledb; using clubstar.iplug.dataop;

Namespace Clubstar.dataop {///

/// Authority_Identify_Proxy's summary description. // Permissions Identification Agent class uses Proxy design mode, and when the system administrator operates on the data table Admin, ////////mmary> public interface authority_identify {bool issystem_admin ( string name, string password); bool Change_Name (string name, string password, string newname); bool change_Password (string name, string password, string newpassword); bool Delete_Admin (string name, string password); OleDbDataReader Select_Admin (string name, string PASSWORD);

// will be proxy class public class admin: authority_identify = condb_op.instance (); private OLEDBDataReader DR;

Private static admin = NULL; // Using a single mode to operate public static admin instance () {if (null == admin) admin = new admin (); returnad;}

public bool isSystem_Admin (string name, string password) {dr = UserTable.ExecuteReader ( "select * from admin where name = '" name.Trim () "' and password = '" password "' and rank = 1" ); If (Dr.hasRows) Return True; Else Return False;}

public bool Change_Name (string name, string password, string newname) {if (isSystem_Admin (name, password)) {UserTable.ExecuteReader ( "update admin set name = '" newname.Trim () "' where name = '" name.Trim () " '"); return true;} else {return false;}} public bool change_Password (string name, string password, string newpassword) {if (isSystem_Admin (name, password)) {UserTable.ExecuteReader ("Update Admin Set Password = ' NewPassword.trim () "' WHERE Name = '" Name.trim () "' "; Return True;} else {returnaf false;}}

public bool Delete_Admin (string name, string password) {if (isSystem_Admin (name, password)) {UserTable.ExecuteReader ( "delect from admin where name = '" name.Trim () "'"); return true;} Else {Return False;}}

public OleDbDataReader Select_Admin (string name, string password) {if (isSystem_Admin (name, password)) dr = UserTable.ExecuteReader ( "select * from admin where name = '" name.Trim () "'"); return dr }}

@ Proxy class: public class AdminProxy {public Admin admin = Admin.Instance (); public string _name, _password; public AdminProxy (string name, string password) {this._name = name; this._password = password;} / * Manage the level of the entire system * / public static int system_admin = 1; public bool change_name (String newname) {returna.change_name (this._name, this._password, newname.trim ());}

public bool Change_Password (string newword) {return admin.Change_Password (this._name, this._password, newword);} public bool Delete_Admin () {return admin.Delete_Admin (this._name, this._password);}

Public oledbdatareader select_admin () {returnid.select_admin (this._name, this._password);

}

} You only need to declare the following: adminProxy test = new adminproxy ("1", "1"); test.change_password ("1");

转载请注明原文地址:https://www.9cbs.com/read-82615.html

New Post(0)