Skip to content

Aspect-Oriented Programming – Is it any good?

March 25, 2009

I’ve been hearing a little about Aspect-Oriented Programming recently, and was wondering what it was all about, and whether it was actually any good.

I was going to write some relatively lengthy introduction, but fortunately Stack Overflow already has what appears to be a reasonably concise comparison with Object-Oriented Programming here.

Erm, what?..

According to the top answer, Wikipedia has one of the best examples for this, where every shape that extends Shape has to call display.update() at the end of its moveBy() methods, and the Aspect-Orientated version just silently hooks in the display.update() call at the end of every moveBy() method, in every derived class, now and forever more.

Erm, isn’t this just bad OO? Isn’t this just solved with a Template Pattern in the base class, where the moving is delegated to the most-derived class, but the display-updating is common to all of them?

And the whole “doing things by magic” thing is deeply disconcerting. I guess that the logging example is slightly more compelling, in that “doing” and “logging” could be considered two encapsulated events, and that the “doing” part should have no knowledge of the “logging” part, or vice versa. Maybe.

I’m just not sure. Maybe they’re right. Despite quoting Wikipedia, the example as presented on Stack Overflow actually talks about set[Blah]() methods, where say a Point might just have a setPoint() method but a line might have setStart() and setEnd(). Maybe you can’t use base-class OO to trigger a display.update() every time something in a derived class changes that might affect the display – what right has the base class in knowing/dictating what does and doesn’t trigger such action? And isn’t setBlah() code smell anyway? It sounds like the sort of thing that goes hand-in-hand with a default constructor, and I think we all know how evil they are.

I don’t know. Like many of these things, I just don’t think that I’ll be able to make up my mind without actually giving it a go.

No comments yet

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: