<p><a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" rel="noreferrer">AOP</a> is an interesting programming paradigm in my opinion. However, there haven't been discussions about it yet here on stackoverflow (at least I couldn't find them). What do you think about it in general? Do you use AOP in your projects? Or do you think it's rather a niche technology that won't be around for a long time or won't make it into the mainstream (like OOP did, at least in theory ;))? </p>

<p>If you do use AOP then please let us know which tools you use as well. Thanks!</p>

[{'answer_id': 20688, 'author': 'Matt McMinn', 'author_id': 1322, 'author_profile': 'https://Stackoverflow.com/users/1322', 'pm_score': 2, 'selected': False, 'text': '<p>We used aspectJ in one of my big projects for quite some time.  The project was made up of several web services, each with several functions, which was the front end for a complicated document processing/querying system.  Somewhere around 75k lines of code.  We used aspects for two relatively minor pieces of functionality.</p>\n\n<p>First was tracing application flow.  We created an aspect that ran before and after each function call to print out "entered \'function\'" and "exited \'function\'".  With the function selector thing (pointcut maybe?  I don\'t remember the right name) we were able to use this as a debugging tool, selecting only functions that we wanted to trace at a given time.  This was a really nice use for aspects in our project.</p>\n\n<p>The second thing we did was application specific metrics.  We put aspects around our web service methods to capture timing, object information, etc. and dump the results in a database.  This was nice because we could capture this information, but still keep all of that capture code separate from the "real" code that did the work.</p>\n\n<p>I\'ve read about some nice solutions that aspects can bring to the table, but I\'m still not convinced that they can really do anything that you couldn\'t do (maybe better) with "normal" technology.  For example, I couldn\'t think of any major feature or functionality that any of our projects needed that couldn\'t be done just as easily without aspects - where I\'ve found aspects useful are the kind of minor things that I\'ve mentioned.</p>\n'}, {'answer_id': 20698, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 5, 'selected': True, 'text': '<p>Yes.</p>\n\n<p>Orthogonal concerns, like security, are best done with AOP-style interception. Whether that is done automatically (through something like a dependency injection container) or manually is unimportant to the end goal.</p>\n\n<p>One example: the "before/after" attributes in <a href="http://www.codeplex.com/xunit" rel="noreferrer">xUnit.net</a> (an open source project I run) are a form of AOP-style method interception. You decorate your test methods with these attributes, and just before and after that test method runs, your code is called. It can be used for things like setting up a database and rolling back the results, changing the security context in which the test runs, etc.</p>\n\n<p>Another example: the filter attributes in <a href="http://www.asp.net/mvc" rel="noreferrer">ASP.NET MVC</a> also act like specialized AOP-style method interceptors. One, for instance, allows you to say how unhandled errors should be treated, if they happen in your action method.</p>\n\n<p>Many dependency injection containers, including Castle Windsor and Unity, support this behavior either "in the box" or through the use of extensions.</p>\n'}, {'answer_id': 20758, 'author': 'Eli Courtwright', 'author_id': 1694, 'author_profile': 'https://Stackoverflow.com/users/1694', 'pm_score': 5, 'selected': False, 'text': '<p>Python supports AOP by letting you dynamically modify its classes at runtime (which in Python is typically called monkeypatching rather than AOP).  Here are some of my AOP use cases:</p>\n\n<ol>\n<li><p>I have a website in which every page is generated by a Python function.  I\'d like to take a class and make all of the webpages generated by that class password-protected.  AOP comes to the rescue; before each function is called, I do the appropriate session checking and redirect if necessary.</p></li>\n<li><p>I\'d like to do some logging and profiling on a bunch of functions in my program during its actual usage.  AOP lets me calculate timing and print data to log files without actually modifying any of these functions.</p></li>\n<li><p>I have a module or class full of non-thread-safe functions and I find myself using it in some multi-threaded code.  Some AOP adds locking around these function calls without having to go into the library and change anything.</p></li>\n</ol>\n\n<p>This kind of thing doesn\'t come up very often, but whenever it does, monkeypatching is VERY useful.  Python also has decorators which implement the Decorator design pattern (<a href="http://en.wikipedia.org/wiki/Decorator_pattern" rel="noreferrer">http://en.wikipedia.org/wiki/Decorator_pattern</a>) to accomplish similar things.</p>\n\n<p>Note that dynamically modifying classes can also let you work around bugs or add features to a third-party library without actually having to modify that library.  I almost never need to do this, but the few times it\'s come up it\'s been incredibly useful.</p>\n'}, {'answer_id': 62881, 'author': 'Chris Canal', 'author_id': 5802, 'author_profile': 'https://Stackoverflow.com/users/5802', 'pm_score': 1, 'selected': False, 'text': "<p>I use AOP heavily in my C# applications.  I'm not a huge fan of having to use Attributes, so I used Castle DynamicProxy and Boo to apply aspects at runtime without polluting my code</p>\n"}, {'answer_id': 97160, 'author': 'Scott Bale', 'author_id': 2495576, 'author_profile': 'https://Stackoverflow.com/users/2495576', 'pm_score': 2, 'selected': False, 'text': '<p>At <a href="http://www.terracotta.org/" rel="nofollow noreferrer">Terracotta</a> we use AOP and bytecode instrumentation pretty extensively to integrate with and instrument third-party software.  For example, our <a href="http://www.terracotta.org/confluence/display/integrations/Spring" rel="nofollow noreferrer">Spring intergration</a> is accomplished in large part by using <a href="http://aspectwerkz.codehaus.org/" rel="nofollow noreferrer">aspectwerkz</a>.  In a nutshell, we need to intercept calls to Spring beans and bean factories at various points in order to cluster them.</p>\n\n<p>So AOP can be useful for integrating with third party code that can\'t otherwise be modified.  However, we\'ve found there is a huge pitfall - if possible, only use the third party public API in your join points, otherwise you risk having your code broken by a change to some private method in the next minor release, and it becomes a maintenance nightmare.</p>\n'}, {'answer_id': 129630, 'author': 'skaffman', 'author_id': 21234, 'author_profile': 'https://Stackoverflow.com/users/21234', 'pm_score': 2, 'selected': False, 'text': "<p>AOP and transaction demarcation is a match made in heaven.  We use Spring AOP @Transaction annotations, it makes for easier and more intuitive tx-demarcation than I've ever seen anywhere else.</p>\n"}, {'answer_id': 147209, 'author': 'Chris R', 'author_id': 23309, 'author_profile': 'https://Stackoverflow.com/users/23309', 'pm_score': 1, 'selected': False, 'text': '<p>We use AOP in our session facade to provide a consistent framework for our customers to customize our application.  This allows us to expose a single point of customization without having to add manual hook support in for each method.</p>\n\n<p>Additionally, AOP provides a single point of configuration for additional transaction setup and teardown, and the usual logging things.  All told, much more maintainable than doing all of this by hand.</p>\n'}, {'answer_id': 213652, 'author': 'Dónal', 'author_id': 2648, 'author_profile': 'https://Stackoverflow.com/users/2648', 'pm_score': 3, 'selected': False, 'text': "<p>I don't understand how one can handle cross-cutting concerns like logging, security, transaction management, exception-handling in a clean fashion without using AOP.</p>\n\n<p>Anyone using the Spring framework (probably about 50% of Java enterprise developers) is using AOP whether they know it or not.</p>\n"}, {'answer_id': 213677, 'author': 'Yes - that Jake.', 'author_id': 5287, 'author_profile': 'https://Stackoverflow.com/users/5287', 'pm_score': 1, 'selected': False, 'text': '<p>The main application I work on includes a script host. AOP allows the host to examine the properties of a script before deciding whether or not to load the script into the Application Domain. Since some of the scripts are quite cumbersome, this makes for much faster loading at run-time.</p>\n\n<p>We also use and plan to use a significant number of attributes for things like compiler control, flow control and in-IDE debugging, which do not need to be part of the final distributed application.</p>\n'}, {'answer_id': 257502, 'author': 'Brian Adams', 'author_id': 32992, 'author_profile': 'https://Stackoverflow.com/users/32992', 'pm_score': 1, 'selected': False, 'text': '<p>We use PostSharp for our AOP solution. We have caching, error handling, and database retry aspects that we currently use and are in the process of making our security checks an Aspect.</p>\n\n<p>Works great for us.  Developers really do like the separation of concerns.  The Architects really like having the platform level logic consolidated in one location.</p>\n\n<p>The PostSharp library is a post compiler that does the injection of the code.  It has a library of pre-defined intercepts that are brain dead easy to implement.  It feels like wiring in event handlers.  </p>\n'}, {'answer_id': 50096076, 'author': 'arif abbas', 'author_id': 5281508, 'author_profile': 'https://Stackoverflow.com/users/5281508', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, we do use AOP in application programming . I preferably use AspectJ for integrating aop in my Spring applications. Have a look at this article for getting a broader prospective for the same.</p>\n\n<p><a href="http://codemodeweb.blogspot.in/2018/03/spring-aop-and-aspectj-framework.html" rel="nofollow noreferrer">http://codemodeweb.blogspot.in/2018/03/spring-aop-and-aspectj-framework.html</a></p>\n'}]
['https://Stackoverflow.com/questions/20663', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1793/']