Pointcut
   HOME

TheInfoList



OR:

In
aspect-oriented programming 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 (an advice) ''without'' modifying t ...
, 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. 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 AspectJ is an aspect-oriented programming (AOP) extension for the Java programming language, created at PARC. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become a widely ...
syntax is considered as de facto standard. Frameworks are available for various programming languages like
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
Perl Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language". Perl was developed ...
,
Ruby Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
, and many more which support pointcuts.


Background

Due to limitations in various programming languages,
cross-cutting concern 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 re ...
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.
Aspect-oriented programming 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 (an advice) ''without'' modifying t ...
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 In computer science, separation of concerns (sometimes abbreviated as SoC) 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 o ...
, 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 In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
. 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.


Expressions

Following are some important pointcut expressions supported by
AspectJ AspectJ is an aspect-oriented programming (AOP) extension for the Java programming language, created at PARC. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become a widely ...
. These expressions can be combined using logical operators. 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

Pointcut languages impact important software properties like
evolvability Evolvability is defined as the capacity of a system for adaptive evolution. Evolvability is the ability of a population of organisms to not merely generate genetic diversity, but to generate '' adaptive'' genetic diversity, and thereby evolve thr ...
and comprehensibility in a negative way. There might be a possibility where there is a need to perform
refactoring In computer programming and software design, code refactoring is the process of restructuring existing source code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structure, ...
to define a correct aspect, which in general should not happen since refactoring is to make code cleaner. It is also not
scalable Scalability is the property of a system to handle a growing amount of work. One definition for software systems specifies that this may be done by adding resources to the system. In an economic context, a scalable business model implies that ...
when there are multiple aspects to be applied on the same code and each aspect requires a different refactoring. 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.


References


External links

*Paper
Back to the Future: Pointcuts as Predicates over Traces
by Karl Klose and Klaus Ostermann *Paper
Remote Pointcut - A Language Construct for Distributed AOP
by Muga Nishizawa,
Shigeru Chiba , known by the stage name , is a Japanese actor, voice actor, narrator, talent and sound director from Kikuchi, Kumamoto. He is affiliated with the talent management firm 81 Produce. He is most known for the roles of Yoshihiro Kira from '' Jo ...
and Michiaki Tatsubori *Paper
Datalog as a Pointcut Language in Aspect-Oriented Programming
*Paper

by Karl J. Lieberherr,
Jeffrey Palm Jeffrey may refer to: * Jeffrey (name), including a list of people with the name *Jeffrey's, Newfoundland and Labrador, Canada *Jeffrey City, Wyoming, United States *Jeffrey Street, Sydney, Australia * Jeffreys Bay, Western Cape, South Africa Art ...
and Ravi Sundaram {{aosd Aspect-oriented software development Aspect-oriented programming