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 point In computer science, a join point is a point in the control flow of a program where the control flow can arrive via two different paths. In particular, it's a basic block that has more than one predecessor. In aspect-oriented programming a set of ...
s. Pointcut specifies where exactly to apply
advice Advice (noun) or advise (verb) may refer to: * Advice (opinion), an opinion or recommendation offered as a guide to action, conduct * Advice (constitutional law) a frequently binding instruction issued to a constitutional office-holder * Advice (p ...
, 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 name. Different frameworks support different Pointcut expressions;
AspectJ 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 us ...
syntax is considered as de facto standard. Frameworks are available for various programming languages like
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
,
Ruby A 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 sa ...
, and many more which support pointcut.


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 rest o ...
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 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 ...
, wherein the programmer
weaves Artificial hair integrations, more commonly known as hair extensions, hair weaves, and fake hair add length and fullness to human hair. Hair extensions are usually clipped, glued, or sewn on natural hair by incorporating additional human or sy ...
(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 stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases sp ...
. 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 of the important pointcut expressions supported by
AspectJ 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 us ...
. 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 throu ...
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 computer 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 by adding resources to the system. In an economic context, a scalable business model implies that a company can increase sales given increased resources. For example, a ...
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 Karl may refer to: People * Karl (given name), including a list of people and characters with the name * Karl der Große, commonly known in English as Charlemagne * Karl Marx, German philosopher and political writer * Karl of Austria, last Austri ...
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, 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 '' JoJo's Bizarre ...
and Michiaki Tatsubori *Paper
Datalog as a Pointcut Language in Aspect-Oriented Programming
*Paper

by Karl J. Lieberherr, Jeffrey Palm and Ravi Sundaram {{aosd Aspect-oriented software development Aspect-oriented programming