Aspect orientation vs object-oriented 1 (Introduction)

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/1

Aspect vs Object-Oriented Programming: when to use it, which one should I use?
Aspect-oriented programming (AOP) claims that it is concerned with problems that traditional Object-Oriented Programming (OOP) cannot completely or directly solve. next we will compare the two technologies with line-by-line to find out where this statement is.


Like most developers, I have been using OOP for many years. therefore, when I find that many traditional OOP problems cannot be completely or directly solved by AOP, I think it is necessary to study how it can help application development. comparing these two technologies will provide us with some useful insights in practical applications. here I have designed a case: An OOP Application, which is suitable for using AOP in some aspects.

This document provides a simple example. I first introduced the problem domain and then gave two solutions: one is using OOP and the other is using AOP. the latter uses JDK1.5, JUnit, and AspectWerkz. finally, I will explain how to write the code.

At the end of this article, you will know everything you need to know about using AOP, including the problems it tries to solve in software design.

Problem domain description
A software company employs a programmer, assigns him a business department, and asks him to report to the manager at any time. when team members fulfill their goals, the Manager will give them corresponding points. the solution required by the company must be able to add a new employee and add points to the current employee. for convenience, we use CSV files to store data.


Figure 1 Solution Model

The class Manager inherits from the class Employee and contains an additional property. A department may contain many employees. multiple departments constitute the company. A class like a company is not considered for the moment, because it is out of the problem domain.

Solution Design
The following flowchart describes the solution design.


Figure 2 interaction between objects (Add a new employee and assign him a department and Manager)
For simplicity, this article only focuses on the necessary details. However, you can also study the code to obtain other information.
[Link] http://www.devx.com/assets/sourcecode/13172.zip#/link]
EmployeeServiceTestCase, A JUnit test case class, simulates an end user, creates new employee records, and assigns departments and managers. it obtains and displays data of all available departments and managers on the graphic interface. to instantiate the domain objects BusinessUnit and Manager, the obtained records are passed to the factory class. then, an Employee object is created by passing a reference to EmployeeService. this service class uses EmployeeFactory to create an object and passes it to EmployeeRepository for persistence.

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.