CSC/ECE 517 Fall 2009/wiki29 VB: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
When Object-Oriented (OO) programming was entering into the field of software development, it changed the way how software was developed. The software systems begun to be viewed as groups of entities and the interaction between those entities, which allowed them to tackle larger, more complicated systems and develop them in less time than ever before. However, OO programming is static, and a thus a change in requirements could have a brought a major impact on development time lines.  
When Object-Oriented (OO) programming was entering into the field of software development, it changed the way how software was developed. The software systems begun to be viewed as groups of entities and the interaction between those entities, which allowed them to tackle larger, more complicated systems and develop them in less time than ever before. However, OO programming is static, and a thus a change in requirements could have a brought a major impact on development time lines.  


Line 26: Line 25:
     System.out.println ("Hello, AOP");
     System.out.println ("Hello, AOP");
   }
   }
   public void sayAnyThing (String s) {
   public void sayAnyThing (String s) {
     System.out.println (s);
     System.out.println (s);
   }
   }
   public static void main (String[] args) {
   public static void main (String[] args) {
     sayHello ();
     sayHello ();

Revision as of 15:36, 9 October 2009

When Object-Oriented (OO) programming was entering into the field of software development, it changed the way how software was developed. The software systems begun to be viewed as groups of entities and the interaction between those entities, which allowed them to tackle larger, more complicated systems and develop them in less time than ever before. However, OO programming is static, and a thus a change in requirements could have a brought a major impact on development time lines.

Aspect-Oriented Programming (AOP) complements OO programming by allowing the developer to dynamically modify the static OO model to create a system that can grow to meet new requirements. Just as objects in the real world can change their states during their lifecycles, an application can adopt new characteristics as it develops.

For example, we develop a web application where a servlet accepts the values of an HTML form, binds them to an object, passes them into the application to be processed, and then returns a response to the user. This basic functionality of the servlet may be very simple, and can be fulfilled with minimum amount of code. But, by the time secondary requirements such as exception handling, security, and logging have been implemented , the size of the code increases to about three times of original. Having said that, it is not mandatory for the servlet to know about the logging or security mechanisms being used, and hence can be called as secondary requirements. Its primary function is to just accept input and process it.

Using AOP , we can dynamically modify our static model to include the code required to fulfill the secondary requirements without having to modify the original static model. We can also keep this additional code in a single location rather than having to scatter it across the existing model, as we would have to if we were using OO on its own.


ASPECTJ


Here are some of the standard terms that would be required to understand AOP concepts. 1.Cross-cutting concerns: Even though most classes in an OO model will perform a single, specific function, they often share common, secondary requirements with other classes. For example, we may want to add logging to classes within the data-access layer and also to classes in the UI layer whenever a thread enters or exits a method. Even though the primary functionality of each class is very different, the code needed to perform the secondary functionality is often identical. 2.Advice: Advice is the extra code that we want to add to our already existing model. 3.Point-cut: Point-cut is the point of execution in the application at which cross-cutting concern needs to be applied. 4.Aspect: Aspect is the combination of the point-cut and the advice. The other terms that appear often in AOP are introductions (where interfaces/methods/fields can be added to existing classes). These hold tremendous potential for developers,

Just as the important facets of OOP are inheritance, encapsulation, and polymorphism, the components of AOP are join points, pointcut, advice, and introduction.

Let's consider the following example to understand this better.

public class TestClass {
 public void sayHello () {
   System.out.println ("Hello, AOP");
 }
 public void sayAnyThing (String s) {
   System.out.println (s);
 }
 public static void main (String[] args) {
   sayHello ();
   sayAnyThing ("ok");
 }
}