In aspect-oriented programming, a pointcut is a set of join points. A pointcut specifies where exactly to apply an 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 names. 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 pointcuts [citation needed].

Background

edit

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

edit

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

edit

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

edit

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

execution(void User.setPassword(password))

This pointcut matches execution of the User.setPassword method.

call(void User.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

edit

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]

References

edit
  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. ^ a b "Inductively generated PointCuts to support refactoring to Aspects". 2004. CiteSeerX 10.1.1.2.594.
edit

📚 Artikel Terkait di Wikipedia

Aspect-oriented programming

the code, instead separately specifying which code is modified via a "pointcut" specification, such as "log all function calls when the function's name

Join point

predecessor. In aspect-oriented programming a set of join points is called a pointcut. A join point is a specification of when, in the corresponding main program

Distributed AOP

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

AspectJ

VisitAspect { void Point.acceptVisitor(Visitor v) { v.visit(this); } } Pointcuts Allow a programmer to specify join points (well-defined moments in the

Aspect weaver

weavers take instructions known as advice specified through the use of pointcuts and join points, special segments of code that indicate what methods should

Spring Framework

container. Spring 2.0 added more integration with AspectJ; for example, the pointcut language is reused and can be mixed with Spring AOP-based aspects.[citation

DTrace

each probe is associated with an action. These probes are comparable to a pointcut in aspect-oriented programming. Whenever the condition for the probe is

Data-driven programming

aspect-oriented programming, where when a join point (condition) is reached, a pointcut (action) is executed. A similar paradigm is used in some tracing frameworks