Dynamic proxies implement AOP:
AOP is actually very early in accordance with a number of things to do, the reason why do not dare to say, because it is what? How to do it? Made out of something, isn't it? have been looking at the data, the data to follow up, and later found that AOP is getting bigger, and much of the information and the idea of AOP itself conflict, so there is much to learn.
the role of AOP:
You can dynamically add and remove missed notes on facets without affecting the original execution code.
AOP Proxy implementations:
Static proxy implementations:
Use the diagram to illustrate the following:
Interface entity class:
<span style= "FONT-SIZE:18PX;" > namespace aop_test1 { //entity class public class User {public int id {get; set;} Public String name {get; set;} Public String password {get; set;} Override method Public override String ToString () { return "ID:" + ID + "; Name:" + name + ";p assword:" + password;
} } </span>
Interface class:
<span style= "FONT-SIZE:18PX;" >namespace aop_test1 { //interface, data operation public interface Iuser { void Delete (user user); void update (user user); } } </span>
The Real implementation class:
<span style= "FONT-SIZE:18PX;" >using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Namespace Aop_test1 { //iuser Interface implementation Public class Iuserimpl:iuser {public void Delete (user user) { System.Console.WriteLine ("delete user"); } public void update (user user) { System.Console.WriteLine ("Update Users");}} </span>
Static proxy classes:
<span style= "FONT-SIZE:18PX;" > Namespace Aop_test1 {//iuser Decoration class public class Iuserdecorator:iuser { Public Iuser Iuser {get; set;} Public Iuserdecorator (Iuserimpl iuserimpl) {iuser = Iuserimpl; }//delete public void Delete (user user) {beforedelete (user); Iuser.delete (user); AfterDelete (); } protected void BeforeDelete (user user) {Console.WriteLine (DateTime.Now + ": Data backup prior to deletion:"); Console.WriteLine ("Backup data:" + user.) ToString ()); } protected void AfterDelete () {Console.WriteLine ("Delete operation completed."); }//Update public void Update (user user) {beforeUpdate (user); User.name = "Tanweijie"; Iuser.update (user); AfterUpdate (user); } protected void BeforeUpdate (user user) {Console.WriteLine (Dateti Me. Now + ": Data backup prior to update:"); Console.WriteLine ("Pre-Update data:" + user.) ToString ()); } protected void AfterUpdate (user user) {Console.WriteLine ("Update operation completed."); Console.WriteLine ("Updated Data:" + user.) ToString ()); }}} </span>
Run Time:
<span style= "FONT-SIZE:18PX;" > static void Main (string[] args) { User user = new user (); User.ID = 1; User.Name = "Tan"; User.password = "123456"; Iuser Iuser = new Iuserdecorator (new Iuserimpl ()); Iuser.delete (user); Console.WriteLine (); Iuser.update (user); } </span>
As we can see from the above, this is an initial model of AOP, or this is not the true meaning of AOP.
Summary
The code AOP above is implemented in this way:
In fact, the simplest AOP is this:
To be continued .....
In layman's AOP (i)