diff --git a/README.md b/README.md index ecc5cf9..16a6470 100644 --- a/README.md +++ b/README.md @@ -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: