Aspect-Oriented vs object-oriented 4 (in-depth code)

Source: Internet
Author: User

By Narayanan A.R. June 15,200 5
Translate zhangv (derekzhangv.at.hotmail.com)
Original article: http://www.devx.com/Java/Article/28422/0/page/4

In-depth source code

To understand the OOP design required by the sample, please refer to the source code and think about the following questions:
Download

* Analyze the code in the EmployeeServiceTestCase class in the oldway package
* View the testEmployeeCredit Method
* Understand the business-class Employee and BusinessUnit
* Learn service, repository, and factory concepts. These are the main concepts of business-driven design.
* A deeper understanding of the service, repository, and factory classes in the oldway package

To understand AOP, it should be:
* Analyze the EmployeeServiceTestCase class in the newway package
* Check the service, repository, and factory classes, which are similar to the previous one. You only need to let advice intercept the program process.
* Study the definition of aspect class learning point cut

What you need to do to execute a program:
* Download AspectWerkz 2.0 http://aspectwerkz.codehaus.org/
* Set the following environment variables:
Set JAVA_HOME = c: Program FilesJavajdk1.5.0
Set ASPECTWERKZ_HOME = C: aw_2_0_2
Set PATH = % PATH %; % ASPECTWERKZ_HOME % in
Set CLASSPATH =
C: aw_2_0_2libaspectwerkz-2.0.RC2.jar; C: aw_2_0_2libaspectwerkz-jdk5-2.0.RC2.jar; classes; C: junit3.8.1esourceslibjunit. jar
* Decompress the source code and other files.
* Compile the Java file, but do not compile the test case. Otherwise, you will encounter an error during debugging.
* Perform offline debugging. If you extract the file to c: aop and the class file to c: aopclasses, run the following command in the c: aop directory:
% ASPECTWERKZ_HOME % inaspectwerkz-offline etc/aop. xml-cp classes
* The AOP framework modifies classes to inject necessary bytecode.
* Compile the test case and run it using JUnit.

Postscript
When you finish the above work, you should have the following insights:
* Cross-association in the program
* Chinese meanings of AOP
* How to Use AOP to separate the cross-association in the program business layer and use point cut and advice
* Differences in program control flow when OOP and AOP are used in a given scenario

Fortunately, from this article you should also get a new perspective on practical development. you should be confident to use AOP to improve the reusability of design, modeling, and code in the project. at least, you can start to use AOP to process logs, errors, and persistence.

I personally think that the learning curve of AOP is steep, especially when we understand the syntax of point cuts. ideally, we use OOP to design the business model and use AOP to transfer the cross-association in the business class so that the code is concise and readable.

One disadvantage of AOP is that debugging becomes difficult, because, unlike OOP, the process is complex and the interaction is determined by the compilation or execution period. I am going to prepare some automated tools to solve this problem in the future.

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.