This is to certify that project entitled “Aspect oriented programming”, submitted by “Sudhanshu Mathur”, students of final year B.Tech in Information Technology, JAIPUR ENGINEERING COLLGE, KUKAS, JAIPUR was completed under my supervision and their work was found satisfactory and I found them sincere towards their work.
Head, Department of IT
Place: - Jaipur
Date: - 14/03/2012
This report intends to reflect some of the basics required for building a project i.e. “Aspect oriented programming and related fundamentals”. The total aspects have been formulated and presented on the basis of ideas and information gathered from emerging technology.
This report has been written in response to a comprehensive study. The report mentions and evaluates the various aspects, through analysis of the various facts and figures. Accuracy and precision has been given prime consideration, while compiling the report.
Let me in this page express my heartiest gratitude to all those who helped me in various stages of this study. I am very much thankful to Dr. G.D.SHARMA, Director (Academics), JEC College, Kukas, and Mr. Shiv Kumar Agarwal, HOD, Dept. Of IT for giving me permission to undergo the seminar and providing all other necessary facility. I would also thankful to Mr. Manoj Raman and Ms Anuradha, Sr. Faculty of IT department for their kind support.
During the seminar period all the staff member of Deptt. have helped me with there skills. Here by I express my sincere thanks to seminar coordinator. Also I am thankful to other technical staff of the Deptt. who have helped me to complete my seminar successfully. I wish to express my deep sense of gratitude to my seminar guide for her valuable guidance and kind cooperation without which this project would have not been possible.
Sudhanshu Mathur (IT08059)
Jaipur Engineering College
NAME OF THE CHAPTER
GOALS OF ASPECT ORIENTED PROGRAMMING
CROSS CUTTING CONCERNS
OVERVIEW OF ASPECT ORIENTED PROGRAMMING
ARCHITECTURE OF AOP
MOTIVATION AND BASIC CONCEPTS
COMPARISION TO OTHER PROGRAMMING PARADIGMS
ADVANTAGES & DISADVANTAGES
Insoftware engineering, the programming paradigms of Aspect- Oriented programming (AOP), and Aspect- Oriented Software development (AOSD) attempt to aidprogrammers in the separation of concerns, specifically cross-cutting concerns, as an advance inmodularization. AOP does so using primarily language changes, while AOSD uses a combination of language, environment, and method.Separation of concerns entails breaking down a program into distinct parts that overlap in functionality as little as possible. All programming methodologies including procedural programming and object-oriented programming support some separation and encapsulation ofconcerns (or any area of interest or focus) into single entities. For example, procedures, packages,classes, and methods all help programmers encapsulate concerns into single entities. But some concerns defy these forms of encapsulation. Software engineers call these crosscutting concerns,because they cut across many modules in a program. Logging offers one example of a crosscutting concern, because a logging strategynecessarily affects every single logged part of the system. Logging thereby crosscuts all logged classes and methods.AOP is a new technology for separating crosscutting concerns into single units calledaspects. An aspect is a modular unit of crosscutting implementation. It encapsulates behaviour that affects multiple classes into reusable modules. Typically, an aspect is scattered or tangled as code, making it harder to understand and maintain. It is scattered by virtue of the function (such as logging) being spread over a number of unrelated functions that might use its function, possibly in entirely unrelated systems, different source languages, etc. That means to change logging can require modifying all affected modules. Aspects become tangled not only with the mainline function of the systems in which they are expressed but also with each other. That means changing one concern entails understanding all the tangled concerns or having some means by which the effect of changes can be inferred.
Aspects emerged out of object-oriented programming and computational reflection. AOP languages have functionality similar to, but more restricted than metaobject protocols. Aspects relate closely to programming concepts like subjects, mixins, and delegation. Other ways to use aspect-oriented programming paradigms include Composition Filters and the hyperslices approach. Since at least the 1970s, developers have been using forms of interception and dispatch-patching that resemble some of the implementation methods for AOP, but these never had the semantics that the crosscutting specifications provide written in one place.
Designers have considered alternative ways to achieve separation of code, such as C#'s partial types, but such approaches lack a quantification mechanism that allows reaching several join points of the code with one declarative statement.
Aspect Oriented Programming (AOP) is a promising new technology for separatingcrosscutting concerns that are usually hard to do in object-oriented programming . Now-a-days,object-oriented programming (OOP) has become the mainstream programming paradigm where real world problems are decomposed into objects thatabstractbehavior and data in a single unit.OOP encourages software re-use by providing design and language constructs formodularity, encapsulation,inheritance, and polymorphism. Although OOP has met great successin modelling and implementing complex software systems, it has its problems. Practical experience with large projects has shown that programmers may face some problems with maintaining their code because it becomes increasingly difficult to cleanly separate concerns into modules. An attempt to do a minor change in the program design may require several updates to alarge number of unrelated modules. AOP is a new technology for separating crosscutting concerns into single units calledaspects. An aspect is a modular unit of crosscutting implementation. It encapsulates behaviors thataffect multiple classes into reusable modules. With AOP, we start by implementing our project using our OO language (for example, Java), and then we deal separately with crosscuttingconcerns in our code by implementing aspects. Finally, both the code and aspects are combinedinto a final executable form using an aspect weaver. As a result, a single aspect can contribute tothe implementation of a number of methods, modules, or objects, increasing both reusability andmaintainability of the code. Incomputing,Aspect-oriented-programming(AOP) is a programming paradigmwhich aims to increasemodularityby allowing theseparation ofcross-cutting concerns. AOP forms a basis foraspect-oriented software development. AOP includes programming methods and tools that support the modularization of concerns at the level of the source code, while "aspect-oriented software development" refers to a whole engineering discipline.
Question arises that what actually computing is and what we have to do for that….
Computingis usually defined as the activity of using and improvingcomputer hardwareandsoftware. It is the computer-specific part of information technology.Computer science(or computing science) is the study and the science of thetheoretical foundations of information and computationand their implementation and application in computer systems.
Aspect-oriented programming entails breaking down program logic into distinct parts (so-called concerns, cohesive areas of functionality). Nearly all programming paradigms support some level of grouping and encapsulation of concerns into separate, independent entities by providing abstractions (e.g., procedures, modules, classes, methods) that can be used for implementing, abstracting and composing these concerns. But some concerns defy these forms of implementation and are called crosscutting concerns because they "cut across" multiple abstractions in a program.
Logging exemplifies a crosscutting concern because a logging strategy necessarily affects every logged part of the system. Logging thereby crosscuts all logged classes and methods.
All AOP implementations have some crosscutting expressions that encapsulate each concern in one place. The difference between implementations lies in the power, safety, and usability of the constructs provided. For example, interceptors that specify the methods to intercept express a limited form of crosscutting, without much support for type-safety or debugging. AspectJ has a number of such expressions and encapsulates them in a special class, an aspect. For example, an aspect can alter the behavior of the base code (the non-aspect part of a program) by applying advice (additional behavior) at variousjoin points (points in a program) specified in a quantification or query called a pointcut (that detects whether a given join point matches). An aspect can also make binary-compatible structural changes to other classes, like adding members or parents.
Starting from or! and other primitive filters, the programmer could work up to the definition of a filter that selects just those black pixels on a horizontal edge, returning a new image consisting of just those boundary pixels.
Aspect-oriented programming (AOP) better separates concerns than previous methodologies, thereby providing modularization of crosscutting concerns. In the early days ofcomputer science, developers wrote programs by means of direct machine-level coding. Unfortunately, programmers spent more time thinking about a particular machine'sinstructionset than the problem at hand. Slowly, we migrated to higher-level languages that allowed some abstraction of the underlying machine. Then came structured languages; we could now decompose our problems in terms of the procedures necessary to perform our tasks. However, as complexity grew, we needed better techniques. Object-oriented programming (OOP). Let us view a system as a set of collaborating objects. Classes allow us to hide implementation details beneath interfaces. Polymorphisms provided a common behavior and interface for relatedconcepts, and allowed more specialized components to change a particular behaviour withoutneeding access to the implementation of base concepts.Programming methodologies and languages define the way we communicate withmachines. Each new methodology presents new ways to decompose problems: machine code, machine-independent code, procedures, classes, and so on. Each new methodology allowed a more natural mapping of system requirements to programming constructs. Evolution of these programming methodologies let us create systems with ever increasing complexity. The converse of this fact may be equally true: we allowed the existence of ever more complex systems because these techniques permitted us to deal with that complexity. Aspect-oriented programming (AOP) better separates concerns than previousmethodologies, thereby providing modularization of crosscutting concerns.
Good modularity XML parsing
URL pattern matching in org.apache.tomcat
red shows relevant lines of code
nicely fits in two boxes (using inheritance)
Good modularity URL pattern matching
URL pattern matching in org.apache.tomcat
red shows relevant lines of code
nicely fits in two boxes (using inheritance)
Implications of Non-modularization
same fragment of code in many places
Difficult to reason about
the big picture of the tangling isn’t clear
Difficult to change
have to find all the code involved
and be sure to change it consistently
and be sure not to break it by accident
Before we delve too deeply into AOP, let's introduce some terminology to help us understand the concepts. Cross-cutting concerns: Even though most classes in an OO model will perform a single,specific function, they often share common,secondaryrequirements 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.
Advice: This is the additional code that you want to apply to your existing model. In our example, this is the logging code that we want to apply whenever the thread enters or exits a method.
Point-cut: This is the term given to the point of execution in the application at which cross-cutting concern needs to be applied. In our example, a point-cut is reached when the thread enters a method, and another point-cut is reached when the thread exits the method.
Aspect: The combination of the point-cut and the advice is termed an aspect. In the example below, we add a logging aspect to our application by defining a point-cut andgiving the correct advice. Aspects should have the following properties: robust (change to one aspect should have a limited impact on other aspects), systemic (they affect the target program at many differentplaces), cross-cutting each other (in the target program information about one aspect is mixed with information about other aspects), loosely coupled (an aspect should not know thedetails of other aspects), contain join points (which are used to combine the aspects).
CROSS- CUTTING CONCERNS Separation of concerns entails breaking down a program into distinct parts that overlap in functionality as little as possible. All programming methodologies including proceduralprogramming and object-oriented programming support some separation and encapsulation ofconcerns (or any area of interest or focus) into single entities. For example, procedures, packages, classes, and methods all help programmers encapsulate concerns into single entities. But some concerns defy these forms of encapsulation. Software engineers call these crosscutting concerns,because they cut across many modules in a program. An example of crosscutting concerns is "logging," which is frequently used in distributedapplications to aid debugging by tracing method calls. Suppose we do logging at both the beginning and the end of each function body. This will result in crosscutting all classes that haveat least one function. Other typical crosscutting concerns include context-sensitive error handling, performance optimization, and design patterns.Crosscutting concerns may exist in some programs, especially large ones. However, insome situations, redesign of the system might transform a crosscutting into an object. AOP assumes that crosscutting concerns may exist in programs and can't be re-factored out of the design in all situations.