Possible uses for aspect oriented programming

February 25, 2008 at 2:36 pm Leave a comment

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…)


Entry filed under: Uncategorized. Tags: , .

A book on parsing Principles of graphical design

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

February 2008
« Jan   Mar »

%d bloggers like this: