Aspect Oriented Programming’ As Executing the Code Whenever a Program Shows Certain Behaviors

Aspect Oriented Programming’ As Executing the Code Whenever a Program Shows Certain Behaviors

Journal of Advance Research in Computer Science & Engineering ISSN: 2456-3552 Programming using Aspects Authors: 1. Saurabh Saxena 2. Meena Kumar Assistant Professor, DIRD Delhi Assistant Professor, DIRD Delhi E-mail: [email protected] e-mail: [email protected] Abstract : We can define an ‘Aspect oriented programming’ as executing the code whenever a program shows certain behaviors. Aspects are an additional unit of modularity. Aspects can be reused. By reducing code tangling it makes it easier to understand what the core functionality of a module is. An “aspect weaver” takes the aspects and the core modules and composes the final system. Volume-2 | Issue-3 | March,2015 | Paper-13 87 Journal of Advance Research in Computer Science & Engineering ISSN: 2456-3552 Abstract : We can define an ‘Aspect oriented Proving a theorem by programming’ as executing the code finding values for the free whenever a program shows certain variables behaviors. Aspects are an additional unit Prolog, Haskell of modularity. Aspects can be reused. By Object-oriented programming reducing code tangling it makes it easier (OOP) to understand what the core Organizing a set of functionality of a module is. An “aspect objects, each with its own weaver” takes the aspects and the core set of responsibilities modules and composes the final system. Smalltalk, Java, C++ (to some extent) Introduction Aspect-oriented programming In the evolution age of computers where (AOP) every one is almost dependent on Executing code whenever computers for various tasks, there is a a program shows certain big challenge for software developers to behaviors provide the tools that meet the AspectJ (a Java requirement of the layman and of course, extension) the security to his valuable data. Does not replace O-O From the beginning of this changing era, programming, but rather there are many paradigms in complements it programming according to the technological changes. These Programming using Aspects programming paradigms can be OOPS is considered as a security tool for data as classified as :- it provide the ‘data hiding’ from the external . users. Everything in OOPS is organized in Procedural programming objects and each object has its own data and Executing a set of functions to work on. Programming languages commands in a given like JAVA, C++ etc provide a very smart way to sequence do the things but there are certain anomalies to Fortran, C, Cobol OOPS as:- Functional programming a) Some programming tasks cannot Evaluating a function be neatly encapsulated in objects, defined in terms of other but must be scattered throughout functions the code. Some of the tasks are :- Lisp Logic programming Volume-2 | Issue-3 | March,2015 | Paper-13 88 Journal of Advance Research in Computer Science & Engineering ISSN: 2456-3552 Logging (tracking – System wide concerns program behavior to a that span multiple file) modules. Profiling (determining – Cuts across the typical where a program spends division of responsibility. its time) • OOP creates a coupling between Tracing (determining core and crosscutting concerns. what methods are called • AOP aims to modularize when) crosscutting concerns. Session tracking, session expiration The cross cutting concerns can be Special security explained using an example as:- management Let consider the UML for a simple b) The result is crosscutting code-- figure editor in which there are two the necessary code “cuts across” concrete classes of figure element, many different classes and points and lines. The concern that the methods screen manager should be notified The cross cutting has the following whenever a figure element moves. consequences: - This requires every method that --- Redundant code moves a figure element to do the --- Difficult to reason about notification. --- Non-explicit structure --- The big picture of the Now we can define the core of aspect tangling isn’t clear oriented programming i.e ‘aspects’. --- Difficult to change An ‘aspect’ can be understood as:- --- Have to find all the code It is a modular units that cross-cut the involved... structure of other modular units. It is --- and be sure to change it defined in terms of partial information consistently from other units. It exist in both design --- and be sure not to break it and implementation phases. by accident --- Inefficient when crosscutting Also we can define an ‘Aspect oriented code is not needed programming’ as • In AOP crosscutting concerns are There are various crosscutting concerns implemented in aspects instead as:- of fusing them into core modules. • AOP addresses behaviors that • Aspects are an additional unit of span many, often unrelated, modularity. modules. • Aspects can be reused. • Core Concerns: • By reducing code tangling it – Primary core makes it easier to understand functionality. what the core functionality of a – Central functionality of a module is. module. • An “aspect weaver” takes the • Crosscutting Concerns: aspects and the core modules and composes the final system. Volume-2 | Issue-3 | March,2015 | Paper-13 89 Journal of Advance Research in Computer Science & Engineering ISSN: 2456-3552 The ‘weaving’ is a set of rules that specify how to integrate the final system. A pointcut named “move’ that It can be implemented in various ways: chooses various method calls: – Source to source translation. pointcut move(): – Byte code enhancement, call(void FigureElement.setXY(int,int)) first compile source with || call(void Point.setX(int)) original compiler, then || call(void Point.setY(int)) weave aspects into class || call(void Line.setP1(Point)) files. || call(void Line.setP2(Point)); – Just-in-time weaving done by a class loader. – By the language Advice (code) compiler. //that runs before the move pointcut: The JAsCo language supports runtime before (): move() weaving and unweaving. { System.out.println("About to move"); Terminology used for ‘Aspects’ } The terminology used for AOP may // Advice that runs after the move contain the following:- pointcut: 1) Join point after(): move() 2) Point cut { 3) Advice System.out.println("Just successfully 4) Introduction moved"); 5) Aspect } The brief introduction of all these is:- ---- A join point is a well-defined point Join Point in the program flow A join point is a well-defined ---- A point cut is a group of join point in the program flow points We want to execute some ---- Advice is code that is executed at a code (“advice”) each time point cut a join point is reached ---- Introduction modifies the members We do not want to clutter of a class and the relationships up the code with explicit between classes indicators saying “This is ---- An aspect is a module for handling a join point” crosscutting concerns AspectJ provides a syntax ---- Aspects are defined in terms of point for indicating these join cuts, advice, and introduction points “from outside” the ---- Aspects are reusable and actual code inheritable A join point is a point in the ---- Each of these terms will be program flow “where something discussed in greater detail happens” Examples: Let us consider an example to When a method is understand the terminology:- called Volume-2 | Issue-3 | March,2015 | Paper-13 90 Journal of Advance Research in Computer Science & Engineering ISSN: 2456-3552 When an Example point cut designators II exception is thrown When the target object is of type When a variable is SomeType accessed target(SomeType) Pointcuts When the executing code belongs Point cut definitions consist of a to class MyClass left-hand side and a right-hand within(MyClass) side, separated by a colon When the join point is in the The left-hand side control flow of a call to a Test's consists of the point cut no-argument main method name and the point cut cflow(call(void parameters (i.e. the data Test.main())) available when the events happen) Point cut designator wildcards The right-hand side It is possible to use wildcards to consists of the point cut declare point cuts: itself execution (* *(..)) Example point cut: Chooses the point cut setter(): call(void setX(int)); execution of any The name of this point method regardless cut is setter of return or The point cut has no parameter types parameters The point cut itself is call(* set(..)) call(void setX(int)) Chooses the call The point cut refers to to any method any time the void named set setX(int) method is called regardless of return or Example point cut designators I parameter type When a particular method body In case of executes: overloading there execution(void may be more than Point.setX(int)) one such set When a method is called: method; this call(void Point.setX(int)) pointcut picks out When an exception handler calls to all of them executes: handler(ArrayOutOfBoun Point cut designators based on types dsException) You can select elements based on When the object currently types. For example, executing (i.e. this) is of type execution(int *()) Some Type: Chooses the this(SomeType) execution of any method with no Volume-2 | Issue-3 | March,2015 | Paper-13 91 Journal of Advance Research in Computer Science & Engineering ISSN: 2456-3552 parameters that made from the returns an int code in Point’s or call(* setY(long)) Line’s type Chooses the call declaration to any setY within(*) && method that takes execution(*.new(int)) a long as an Chooses the argument, execution of any regardless of constructor taking return type or exactly one int declaring type argument, call(* Point.setY(int)) regardless of

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us