About JavaSome people say that AOP and DOTNET attribute are concepts and attribute are technologies and cannot be confused. However, if you want to avoid affecting the original class hiberarchy, use the cross-cutting method to influence the behavior of class or method. netProgramIf you say to Java programmers, they will definitely say AOP. So whether it's a concept or a technology, as long as they do something the same, we don't need to care too much about his name. only their functions are well described.
First, both AOP and DOTNET attribute belong to Declarative Programming (DP). The main purpose of DP is to solve the code reuse problem. without changing the code and less code, change the system functions by replacing the adapter. The idea is very similar to the options or style in (Object Oriented Programming) oop. The difference is that in OOP, you have to set AA. options = .. or setstyle (AA ,..) put it in the code, this is more flexible, but once the function changes, the programer must view the entire program to find the correspondingCodeAnd may be more than one, which increases the maintenance cost of the system.
As far as I know, most of AOP uses XML to configure and manage the adapter, so you don't need to change the code. You only need to change the XML. This is indeed convenient, but it also brings about management problems, for example, we use the following code to configure and initialize the adapter environment.
-- Copy Spring framework open document, thanks from nuke
Applicationcontext CTX = new
Filesystemxmlapplicationcontext ("bean. xml ");
Action action = (Action) CTX. getbean ("theaction ");
In many cases, we encapsulate the code for initializing the adapter into the construction of the base class in the framework. However, when we use many AOP-based frameworks during system development, the system must contain a lot of XML, other people cannot know exactly what the system is executing from the system code. They need to find the XML Used in the framework documentation or code, in XML, You can see which element is for which adapter, which also increases the maintenance cost of the system. Some ide support can alleviate some problems, such as adding spring preparation plug-ins in JBuilder and eclipse to help modify XML.
DOTNET attribute introduces the attribute target concept. The target corresponds to the basic elements of code, such as method, class, and assembly (APP), such
[Webmethod]
Procedure AAA (..);
The advantage of doing so is simply to narrow the adapter's search range in the Code, the programer only needs to view the target, and the second is that the adapter is configured in the code, the programer does not need to find the corresponding XML and element everywhere,
The disadvantage is that re-compile is required after attribute modification, which is not as convenient as AOP, but it also avoids cost caused by AOP reflection. programmer can also find typo problems through compiling error.
At present, similar syntaxes are also introduced in Java 5. For example, the following example shows how to implement dependency injection in ejb3, which is similar to annotations in Java XDoclet.
@ EJB (name = "Calculator", jndiname = "org. JBoss. Tutorial. injection. Bean. Calculator ")
Public void setcalculator (calculator C)
{
Set = C;
}