I have seen the design mode for a while. It can also be improved to the objective technology. I can't excite it. I will not be exclusive. I will take it out with everyone. I don't know how to write. Today is to say is the proxy model, the agent mode is in me.
I didn't understand the true meaning of this book until I saw the meaning of the agent model when I saw the code of the JIVE Forum yesterday. ?????????????????????????????????????
??????????????????????????????????????????? ??????????????????????????????????????????? ??????????????????????????????????????????????
> 阎 宏
Now there is a task is to register users, we can write code with ordinary ways, but we now study model models must use the idea of model, :)
Let's take a look at the following, this is an abstract class (all code only give an example, not complete)
??? function getId (): integer; virtual; abstract; ??? function getusername (): string; virtual; abstract; ??? function getName (): string; virtual; abstract; ?? ? function getEmail (): string; virtual; abstract; ??? function getPassword (): string; virtual; abstract; ??? procedure setUserName (name: string); virtual; abstract; ??? procedure setName (name: string ); virtual; procedure setpassword (password: string); virtual; abstract; ??? procedure setemail (email: string); virtual; abstract ;?
This type means that it is specified for the user's interface, here is not fine, let's take a look at the agent class of this user class.
? Tuserproxy = class (tuser)? Private ??? fuser: tuse; public ??? function getId (): integer; override; ??? function getUsername (): string; override; ??? function getname (): string; override; ??? function getEmail (): string; override; ??? function getPassword (): string; override; ??? procedure setUserName (name: string); override; ??? procedure setName (name: string ); override; ??? procedure setPassword (password: string); override; ??? procedure setEmail (email: string); override; ??? function CheckExist (username: string) ;? public ??? constructor Create (AUser : Tuse; virtual ;? End
Constructor tuserproxy.create (auser: tuse); begin? fuse: = auser; end; function tuserproxy.getemail: string; begin? result: = fuser.Getemail (); end;
// ETC.
Unit dbuser;
Interface
User, UserProxy, ConnectionManager, Sysutils, AdoDB, DB, Forms
Const? //? INSERT_USER = 'INSERT INTO MUSER (UserID, Username, Name, Email, Password)' 'Value (' ????????????? ': userid,: username,: Name,: email,: password) ';? load_user ?? =' select * from muker where userid =: userid ';? delete_user =' delete from murse where userid =: userid ';? update_user =' Update Muser set () ';? //
TYPE? TDBUSER = Class (tuser) ??? fconnection: tadoconnection; ??? fadoQuery: ?? tadoquery; ??? fusername: string; ??? fuSelname: string; ??? fname: string ;? ?? fpassword: string; ??? femail: string ;? public ??? function getId (): integer; override; ??? function getusername (): string; override; ??? function getname (): string; override "??? function getemail (): string; override; ??? function getpassword (): string; override; ??? procedure setUsername (name: string); Override; ??? procedure setName (name: string); Override ; ??? procedure setPassword (password: string); override; ??? procedure setEmail (email: string); override; ??? procedure Insert (); ??? procedure SaveToDb (); ??? procedure getProperty (userID : Integer); ??? constructor Create (userID: Integer; userName: string; name: string; password: string; email: string); overload; ??? constructor Create (); overload; ??? property UserName: string Read GetUsername Write SetUserName; ??? Property Name: String Read GetName Write SetName; ??? Property Pass Word: String Read GetPassword Write SetPassword; ??? Property Email: String Read GeTemail Write SetEmail ;? End; This can check if the user has existed or other logic can be implemented in this proxy class (there are many real business logic, not only Check if the user exists), and the task of adding the user is handed over to the TDBuser class, the advantage is that the advantage is to expand without code changes!
BY CLH