Week 7 Aspect Oriented Programming Flashcards

1
Q

What are Cross-cutting concerns?

A

Cross-cutting-concerns are functionalities used throughout an application (it “cuts” across different layers, classes, methods, etc.)

Examples: logging, security, validation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an Aspect?

A

An Aspect is a class that contains different Advice (structured as methods)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where is the @Aspect annotation from?

A

@Aspect is from the AspectJ library, which is a full AOP framework, but Spring AOP can also utilize AspectJ annotations

Note: We can annotate our class with @Aspect to address a particular concern

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is AspectJ? What is the advantage and disadvantage?

A

AspectJ is a fully fledged ORIGINAL AOP framework that provided the ability to write AOP code in an annotation based format.

Advantage: More functionality than Spring AOP
Disadvantage: Harder to Use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some features of Spring AOP?

A

To make use of annotations, Spring AOP understands AspectJ annotations

Less functionality than AspectJ

Easier to use

Uses “runtime-weaving”, which is a process where code is “wrapped” during runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a Join Point?

A

A join point is the location that is “intercepted” by the advice code

A JoinPoint is represented by method execution

So when some method is invoked, the advice will intercept it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a PointCut?

A

A pointcut is a predicate (similar to regular expressions) that indicates WHAT we actually want to intercept

Used to signify the actual JoinPoint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Advice?

A

Advice is the actual code that will run during interception of a join point (specified by a pointcut expression)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some types of Advice?

A

@Before: Advice that will execute before the JoinPoint is executed

@After: Advice that will execute after the JoinPoint is executed (whether it throws an exception or returns successfully)

@AfterReturning: Advice that will execute after the JoinPoint is executed only when there is a successful return with no exception thrown

@AfterThrowing: Advice that will execute after the JoinPoint is executed only when a particular exception is thrown

@Around: Allows for the intercepting of a method both before and after

Can do things like stop the execution of the JoinPoint, or even stop an exception from propagating

Ex. a method mapped to an endpoint
-Using @Around advice, we can actually prevent the endpoint from executing if a condition is not met (ex. current user is not an Admin)

@Around is the MOST POWERFUL type of advice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What can JoinPoint interface do?

A

gives us access to the target object

allows us to gain information such as the method signature, method parameters, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What can ProceedingJoinPoint interface do?

A

Used to handle @Around advice

gives access to the .proceed() method, which will actually execute the JoinPoint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some Types of PointCut Expressions?

A

@annotation: This one can be used for any method annotated with the specified annotation

execution: Most common, specifies which methods to have as our JoinPoints

modifiers-pattern: public private protected default

return-type: void, String, int, boolean, com.revature.gradifysb.model.Assignment

declaring-type-pattern: class name that the method belongs to

Parameter pattern wildcards:
- (): match a method with no arguments
- (*): matches a method with 1 argument of any type
- (..): matches a method with 0 or more arguments of any type

Combine pointcuts
- && (AND)
- || (OR)
- ! (NOT)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define Aspect.

A

Aspect: the class that contains advice methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define Advice:

A

Advice: a method that will execute for a particular Join Point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define JoinPoint:

A

Join Point: the actual method being intercepted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Define PointCut Expression:

A

Pointcut expression: an expression that indicates what method(s) should be the Join Point