Aspect oriented programming promises to deal with cross cutting concerns, but I'm not completely sold on it yet. Have there been any other attempts to deal with this problem?
|
|
When possible, you can encapsulate cross-cutting concerns into separate modules that are then used throughout the app via dependency injection. This allows you to somewhat decouple the cross-cutting concern implementation from it's use throughout the code. This doesn't always work elegantly, though. That's the reason people are trying to address the issue with things like AOP. |
|||
|
|
|
Two other options that I haven't seen explored yet: Functional Programming with Monads and Arrows In FP you represent a cross-cutting concern like anything else: as something you pass in on a function call. Since doing that explicitly gets tedious, you can use Monads (or maybe Arrows) to hide away the extra information being passed along. The most common AOP example is logging. With Monads, you would create a "Logger" monad that keeps a list of messages. Any functions you perform through the LoggerMonad have the ability to post a log message. With Arrows, you would model the entire data flow of the application, and would work a logging routine into the model where appropriate. I think. Arrows are pretty complex. Entity/Component-Based Programming Something I've been researching and experimenting with for a game engine. Instead of "objects" like in OOP, you decompose everything into packets of data (components) and services that operate over a type of component. Components are grouped together by common IDs, like in a relational database, and groups of linked components are the Entities. To add logging in such a system, you would add a new logging service the triggers based on which components are passed through it. Both methods allows for one to easily work a cross-cutting change in very easily, but both are high-level architectural models. So you would probably need to be using them from the beginning. The Component model can, theoretically, be worked into an existing OOP system. I guess monads could be too if your language is powerful enough. |
|||
|
|
There are several ways to tackle the problems of crosscutting concerns:
For all of these, I think studying AOP is appropriate. AOP can help you expand your conceptions of code, even if you don't use an AOP language. |
||||
|
|
|
In general tagging code elements with a declarative feature, but specifically the Attribute system in the C#/.NET/Mono world. |
|||||||||||||
|
|
I'm no expert on AOP, but from reading about it over the years, it has always seemed like a weaker form of the metaprogramming offered by Lisp, especially parts like its metaobject protocol. This should come as no surprise, I suppose: Gregor Kiczales was one of the authors of AMOP, and later wrote AspectJ for Java! |
|||
|
|
