Posts Tagged aspect oriented programming

Possible uses for aspect oriented programming

Aspected oriented programming seemed at first to strike me rather as a solution in search of a problem – and to a degree it still does – So I thought I might try to record various problems that aspect oriented programming might solve as they come to mind or I come across them.

Observer Pattern

The observer pattern tends to result in “notify” function calls being littered throughout the observed object. These can be replaced by a single aspect – thereby separating out the “being observered” behaviour of the observed object from the rest of its behaviour.

To clarify, given some object we can turn it into an observed object by adding a notify method and an aspect that calls this method whenever a modifier is called. If all the modifiers start with “set” or return void then this could be particularly easy to do and if one could be sufficiently consistent throughout one’s codebase – one could imagine having a “subject mixin”, that makes an object observed witout the object being otherwise modifed. All that would be required would be a standard way to identify all the modifiers such that an aspect could be applied to them.

Switching caching of function returns on and off at compile time

One could have a separate caching aspect that adds code before a pointcut to check if a value is in a dictionary, and if so return the stored value. Some care would have to be taken to create this dictionary and store it in an appropriate place.

One could then control caching throughout the application from one locatio.

Restricting access to certain functions based on userĀ 

Our aspect would add code that checks the users permissions and dies and raises exceptions if the permission is not set. (This idea is adapted from here

Doing anything that you might want to do with decorators in python

Decorators in python are quite similar to aspects – but decorators (usually) are applied when the function is defined. (I’m sure one can do crazy things with metaclasses so as to fit aspect oriented programming to python if one so desired… it would all be done at runtime however…)

Add comment February 25, 2008


Meta

Facets

Add new tag AOP apt aspect oriented programming assumes knowledge autiobiographical bash scripts bell books clarity code samples configuration console emacs for the benefit of google functional programming graphical design hacks higher-order functions howtos intention revealing programming keyboard links linux note to self opinions parsing patterns philosophising philosophizing programming python random ideas refactoring removing packages stories succinct svn systems stuff theoretical philosophizing typing vim viper work ethic you probably don't want to read this

Archives

Pages

 

November 2009
M T W T F S S
« Aug    
 1
2345678
9101112131415
16171819202122
23242526272829
30