Programming Ideas-plane-oriented programming (AOP)

Source: Internet
Author: User

When it comes to aspect-oriented programming, we can easily relate to object-oriented programming (OOP). The explanation for these two types of programming is that the two programming ideas are just the point of view of programming.

OOP focuses on the object, how the object behaves and how it is abstracted. How to encapsulate an object that has full properties and behavior. In simple terms, OOP is the encapsulation of a noun.

AOP focuses on behavior and how it divides the behavior of business logic. How to logically divide in logical complex systems (domain division, module partitioning, read partitioning, etc.). In simple terms, AOP is the classification of a series of logical operations.

code example:

Define user users:

 Public class user{  publicint id{get;  Set;}    Public int age{get;  Set;}    Public string name{get;  Set;}}

Operation of the user we can abstract a slice of user information igetuser

 Public Interface igetuser{  User getuserbyid (int  Id);  IEnumerable<User> getusers ();}

Class Defaultgetuser to implement Slice Igetuser

 Public classdefaultgetuser:igetuser{ PublicUser Getuserbyid (intID) {return NewUser{id=1, age= -, name="testname"}; }   PublicIenumerable<user>getusers () {List<User> users=NewList<user>();  for(varI=0;i<Ten; i++) {result. ADD (Newuser{id=i,age=i*Ten, Name=string.format ("testname{0}", I)}); }     returnresult; }}

Sets the proxy object, which can be either a single slice or a series of facets with some kind of association

 Public classgetuserproxy:igetuser{PrivateIgetuser _getuserservice; PrivateILog _log;  Publicgetuserproxy (igetuserservice getuserservice,ilog log) {_getuserservice=Getuserservice; _log=log; }   PublicUser Getuserbyid (intID) {return_getuserservice.getuserbyid (ID); }   PublicUser getusers () {varresult=_getuserservice.getusers (); //proxy class Logic paddingSystem.Threading.Tasks.Task.Factory.StartNew (()=>_log. Log ("p Bulk Read user information"));
return result; } }

Finally, the upper-level invocation of the proxy class is made because the associated slice interface is injected into the proxy class. We can consider using the IOC framework to instantiate proxies, and of course we can inject proxy class construction parameters by reflection to instantiate proxy classes.

Different IOC frameworks are implemented differently, if only simple tests can consider STRUCTMAP,AUTOFAC and so on.

Spring.net to the interpretation of AOP more comprehensive recommendations to understand spring.net;

Programming Ideas-plane-oriented programming (AOP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.