Skip to content

Commit

Permalink
Merge pull request steipete#9 from jasperblues/master
Browse files Browse the repository at this point in the history
Add a more compelling (theoretical) justification for using Aspects
  • Loading branch information
steipete committed May 7, 2014
2 parents 294b393 + 1389607 commit 67464dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ Aspects collects all arguments in the `arguments` array. Primitive values will b

When to use Aspects
-------------------
Aspect-oritented programming (AOP) is used to encapsulate "cross-cutting" concerns. These are the kind of requirements that *cut-accross* many modules in your system, and so cannot be encapsulated using normal Object Oriented programming. Some examples of these kinds of requirements:

* *Whenever* a user invokes a method on the service client, security should be checked.
* *Whenever* a useer interacts with the store, a genius suggestion should be presented, based on their interaction.
* *All* calls should be logged.

If we implemented the above requirements using regular OO there'd be some drawbacks:


Good OO says a class should have a single responsibility, however adding on extra *cross-cutting* requirements means a class that a class is taking on other responsibilites. For example you might have a **StoreClient** that supposed to be all about making purchases from an online store. Add in some cross-cutting requirements and it might also have to take on the roles of logging, security and recommendations.

* Our StoreClient is now harder to maintain
* These cross-cutting requirements are duplicated and spreading throughout our app.

AOP lets us modularize these cross-cutting requirements again. As shown in the examples above cross-cutting requirements can be eithe technical or business focused in nature.

## Here are some concrete examples:


Aspects can be used to **dynamically add logging** for debug builds only:

Expand Down

0 comments on commit 67464dd

Please sign in to comment.