Pointcut

Last updated

In aspect-oriented programming, a pointcut is a set of join points. Pointcut specifies where exactly to apply advice, which allows separation of concerns and helps in modularizing business logic. [1] Pointcuts are often specified using class names or method names, in some cases using regular expressions that match class or method name. Different frameworks support different Pointcut expressions; AspectJ syntax is considered as de facto standard. Frameworks are available for various programming languages like Java, Perl, Ruby, and many more which support pointcut.

Contents

Background

Due to limitations in various programming languages, cross-cutting concern has not modularized. Cross-cutting concern refers to parts of software that logically belong to one module and affect the whole system: this could be security or logging, for example. [2] Aspect-oriented programming tries to solve these cross cutting concerns by allowing programmers to write modules called aspects, which contain pieces of code executed at particular point. The expressions required to select a particular point led to creation of Pointcut Expressions.

Execution

Whenever the program execution reaches one of the join points described in the pointcut, a piece of code associated with the pointcut (called advice) is executed. This allows a programmer to describe where and when additional code should be executed in addition to already-defined behavior. Pointcut permits the addition of aspects to existing software, as well as the design of software with a clear separation of concerns, wherein the programmer weaves (merges) different aspects into a complete application.

Example

Suppose there is an application where we can modify records in a database. Whenever users modify the database, we want to have a log of information regarding who is modifying the records. The traditional way to log is to call a log method just before modifying the database. With aspect-oriented programming, we can apply pointcut to the Modify Database method and have an advice that is called to log the required information. [3]

Expressions

Following are some of the important pointcut expressions supported by AspectJ. These expressions can be combined using logical operators. [4]

execution(voidUser.setPassword(password))

This pointcut matches execution of the User.setPassword method.

call(voidUser.getPassword())

When User.getPassword is called, this pointcut is matched.

handler(ArrayIndexOutOfBounds)

Pointcut will match when there is an ArrayIndexOutOfBounds exception

this(UserType)

Pointcut will match when the object currently executing is of UserType.

target(UserType)

Pointcut will match when the target object is of UserType.

within(UserType)

Pointcut will match when the code executing belongs to UserType.

Criticisms

Pointcut languages impact important software properties like evolvability and comprehensibility in a negative way. There might be a possibility where there is a need to perform refactoring to define a correct aspect, which in general should not happen since refactoring is to make code cleaner. It is also not scalable when there are multiple aspects to be applied on the same code and each aspect requires a different refactoring. [5] In general every aspect will be tightly coupled with an application’s structure as the pointcuts explicitly contain a method’s signature, so when an application changes the pointcut needs to be changed as well. This can be quite problematic for a developer. [5]

Related Research Articles

<span class="mw-page-title-main">Software</span> Non-tangible executable component of a computer

Software is a set of computer programs and associated documentation and data. This is in contrast to hardware, from which the system is built and which actually performs the work.

Computer programming is the process of performing a particular computation, usually by designing and building an executable computer program. Programming involves tasks such as analysis, generating algorithms, profiling algorithms' accuracy and resource consumption, and the implementation of algorithms. The source code of a program is written in one or more languages that are intelligible to programmers, rather than machine code, which is directly executed by the central processing unit. The purpose of programming is to find a sequence of instructions that will automate the performance of a task on a computer, often for solving a given problem. Proficient programming thus usually requires expertise in several different subjects, including knowledge of the application domain, specialized algorithms, and formal logic.

An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools, and a debugger. Some IDEs, such as NetBeans and Eclipse, contain the necessary compiler, interpreter, or both; others, such as SharpDevelop and Lazarus, do not.

In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior. Refactoring is intended to improve the design, structure, and/or implementation of the software, while preserving its functionality. Potential advantages of refactoring may include improved code readability and reduced complexity; these can improve the source code's maintainability and create a simpler, cleaner, or more expressive internal architecture or object model to improve extensibility. Another potential goal for refactoring is improved performance; software engineers face an ongoing challenge to write programs that perform faster or use less memory.

In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code without modifying the code itself, instead separately specifying which code is modified via a "pointcut" specification, such as "log all function calls when the function's name begins with 'set'". This allows behaviors that are not central to the business logic to be added to a program without cluttering the code core to the functionality.

In computer science, separation of concerns is a design principle for separating a computer program into distinct sections. Each section addresses a separate concern, a set of information that affects the code of a computer program. A concern can be as general as "the details of the hardware for an application", or as specific as "the name of which class to instantiate". A program that embodies SoC well is called a modular program. Modularity, and hence separation of concerns, is achieved by encapsulating information inside a section of code that has a well-defined interface. Encapsulation is a means of information hiding. Layered designs in information systems are another embodiment of separation of concerns.

AspectJ is an aspect-oriented programming (AOP) extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become a widely used de facto standard for AOP by emphasizing simplicity and usability for end users. It uses Java-like syntax, and included IDE integrations for displaying crosscutting structure since its initial public release in 2001.

In aspect-oriented software development, cross-cutting concerns are aspects of a program that affect several modules, without the possibility of being encapsulated in any of them. These concerns often cannot be cleanly decomposed from the rest of the system in both the design and implementation, and can result in either scattering, tangling, or both.

<span class="mw-page-title-main">Code injection</span> Computer bug exploit caused by invalid data

Code injection is the exploitation of a computer bug that is caused by processing invalid data. The injection is used by an attacker to introduce code into a vulnerable computer program and change the course of execution. The result of successful code injection can be disastrous, for example, by allowing computer viruses or computer worms to propagate.

In computer programming, Intentional Programming is a programming paradigm developed by Charles Simonyi that encodes in software source code the precise intention which programmers have in mind when conceiving their work. By using the appropriate level of abstraction at which the programmer is thinking, creating and maintaining computer programs become easier. By separating the concerns for intentions and how they are being operated upon, the software becomes more modular and allows for more reusable software code.

Runtime verification is a computing system analysis and execution approach based on extracting information from a running system and using it to detect and possibly react to observed behaviors satisfying or violating certain properties. Some very particular properties, such as datarace and deadlock freedom, are typically desired to be satisfied by all systems and may be best implemented algorithmically. Other properties can be more conveniently captured as formal specifications. Runtime verification specifications are typically expressed in trace predicate formalisms, such as finite state machines, regular expressions, context-free patterns, linear temporal logics, etc., or extensions of these. This allows for a less ad-hoc approach than normal testing. However, any mechanism for monitoring an executing system is considered runtime verification, including verifying against test oracles and reference implementations. When formal requirements specifications are provided, monitors are synthesized from them and infused within the system by means of instrumentation. Runtime verification can be used for many purposes, such as security or safety policy monitoring, debugging, testing, verification, validation, profiling, fault protection, behavior modification, etc. Runtime verification avoids the complexity of traditional formal verification techniques, such as model checking and theorem proving, by analyzing only one or a few execution traces and by working directly with the actual system, thus scaling up relatively well and giving more confidence in the results of the analysis, at the expense of less coverage. Moreover, through its reflective capabilities runtime verification can be made an integral part of the target system, monitoring and guiding its execution during deployment.

Javassist is a Java library providing a means to manipulate the Java bytecode of an application. In this sense Javassist provides the support for structural reflection, i.e. the ability to change the implementation of a class at run time.

The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform. Although the framework does not impose any specific programming model, it has become popular in the Java community as an addition to the Enterprise JavaBeans (EJB) model. The Spring Framework is open source.

The following outline is provided as an overview of and topical guide to computer programming:

e is a hardware verification language (HVL) which is tailored to implementing highly flexible and reusable verification testbenches.

In computing, subject-oriented programming is an object-oriented software paradigm in which the state (fields) and behavior (methods) of objects are not seen as intrinsic to the objects themselves, but are provided by various subjective perceptions ("subjects") of the objects. The term and concepts were first published in September 1993 in a conference paper which was later recognized as being one of the three most influential papers to be presented at the conference between 1986 and 1996. As illustrated in that paper, an analogy is made with the contrast between the philosophical views of Plato and Kant with respect to the characteristics of "real" objects, but applied to software ones. For example, while we may all perceive a tree as having a measurable height, weight, leaf-mass, etc., from the point of view of a bird, a tree may also have measures of relative value for food or nesting purposes, or from the point of view of a tax-assessor, it may have a certain taxable value in a given year. Neither the bird's nor the tax-assessor's additional state information need be seen as intrinsic to the tree, but are added by the perceptions of the bird and tax-assessor, and from Kant's analysis, the same may be true even of characteristics we think of as intrinsic.

<span class="mw-page-title-main">Shotgun surgery</span> Antipattern in software development

Shotgun surgery is an antipattern in software development and occurs where a developer adds features to an application codebase which span a multiplicity of implementors or implementations in a single change. This is common practice in many programming scenarios, as a great amount of programming effort is usually expended on adding new features to increase the value of programming assets. As a consequence, these new features may require adding code in several places simultaneously where the code itself looks very similar and may only have slight variations. Owing to the fast-paced nature of commercial software development, there may not be sufficient time to remodel a system to support the new features trivially. As a consequence, the practice of copy-and-paste programming is prevalent; the code is written in a single place then simply copied to all other places where that implementation is required.

Data, context, and interaction (DCI) is a paradigm used in computer software to program systems of communicating objects. Its goals are:

Aspect-Oriented Programming (AOP) presents the principle of the separation of concerns, allowing less interdependence, and more transparency. Thereby, an aspect is a module that encapsulates a crosscutting concern, and it is composed of pointcuts and advice bodies. The interception of an aspect is performed in a join point, and defined inside a pointcut. Whenever the application execution reaches one pointcut, an advice associated with it is executed. However, this implementation does not take into account separation of concerns in distributed settings.

The following outline is provided as an overview of and topical guide to the Perl programming language:

References

  1. "A Classification of Pointcut Language Constructs" (PDF). Retrieved 29 December 2019.
  2. "Introduction to AspectJ" . Retrieved 14 September 2016.
  3. "JBoss AOP - User Guide". docs.jboss.org. Retrieved 2016-09-14.
  4. "Join Points and Pointcuts" . Retrieved 14 September 2016.
  5. 1 2 "Inductively generated PointCuts to support refactoring to Aspects". 2004. CiteSeerX   10.1.1.2.594 .{{cite journal}}: Cite journal requires |journal= (help)