Test 5 Flashcards
AOP
Aspect-Oriented Programming (AOP) complements OO programming by allowing the developer to dynamically modify the static OO model to deal with cross cutting concerns
Cross-cutting concerns
Concerns which “cross-cut” the class structure, lowering cohesion and increasing coupling.
CCC Consequences
Code Tangling
Code Scattering
Code Tangling
1) Code for CC is mixed with the business logic.
2) Reduces cohesion
Code Scattering
1) Code is duplicated because it is needed in multiple places
2) Reduces coupling
Lock handling Problem
1) Business logic code (put and get) is mixed with concurrency control code resulting in code tangling and poor cohesion
2) Have to add locking code correctly to every business logic code resulting in code scattering
3) Failure to do so would lead to hard to find bugs
4) Need a single, global lock resulting in extra coupling
Lock handling Pros
1) Avoids code scattering and tangling
2) Lock is localised as a private instance variable
3) Reusable simply by writing a new concrete aspect
AOP and Design Patterns Pros
1) Greater modularisation of concerns
2) Avoid code tangling and scattering
3) Easier software evolution
4) Greater code reuse
5) Easier management (easier to split tasks)
6) Cheaper implementation of new features
AOP and Design Patterns Cons
1) Program flow is hard to follow
2) Tendency to use CCC everywhere, leading to poor designs
3) Everybody on the team needs to be up to speed with AOP
4) Tools limited to those which support AOP language in use
AspectJ
1) Java AOP framework
2) Classes and aspects are written separately
3) “woven” together at bytecode generation time
4) Nothing in class code referes to the aspects
AspectJ advice kinds
before - code to be executed before join point
after - code to be executed after join point
around - replaces the code
pointcut - shows where the CC should be applied
AOP and Design Patterns
1) Observer and Singleton are the only ones who have any benefits
2) Pure fabrications have no sensible inheritance relationships outside the pattern
3) Combing patters will make AOP solutions more problematic
Advice
Additional code that you want to apply to your existing model
Join point
Place where CCC crosscuts the code
Point cut
Point of execution in the application at which cross-cutting concern needs to be applied