I have skimmed the online documentation, read the wiki entry, the posts and the blogs, but I'm still puzzled.
I have always been an OO man and I want to know if I need to commit treason.
Seriously, I'm starting a new project soon and I want to make the right choices at the beginning.
What is, in a nutshell, Aspect Oriented Programming ?
In a nutshell, AOP is the ability to inject actions into the typical flow of another program, unobtrusively. It lets you capture class instantiations, method calls, assignments, etc.
Is it simply better then Object Oriented Programming ? Should I unlearn OOP ?
No, and no. It works together with any programming environment that supports it. (See above).
If not, how do I know when to use one or the other ? What are the main differences between the two ?
You use AOP, generally, when you want to implement some sort of actions on hundreds of classes, without manipulating the classes themselves. Typical examples are security (authorisation of the right to call the given method/class) or logging. In my experience, though, I don't use it for this. (I don't use it at all, honestly).
As above, the main difference doesn't really exist, as they aren't comparable. But, say you want to implement logging "normally", you just call the logger at appropriate points:
log.write("hello");
But with AOP, you may create an 'aspect' that attaches to each method call, and log 'Method b called'. The point is that in AOP you approach is more 'shotgun': you attach to everything, or just a small subset. Manually adding logging is generally better.
Can I refact one into the other ?
Not really relevant, see other answers. Again with security, you could swap to an AOP model from a typical OOP model this.IsAllowed() to something like if(callingMethod.HasAttribute(foo)){ allowed = true; }
Hope those answers are useful. Let me know if you want me to expand further.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With