I was talking to Ramnivas Laddad (the person who knows the most about Aspects than anyone I know) at the Philly No Fluff, Just Stuff conference, hoping to dazzle him with an idea I had recently about a cool use for Aspects. My idea: using aspects to implement the Memento pattern for undo. The plan: use attributes in Java 5 to flag which fields are undoable, then write an aspect that injects the appropriate code into an inner class of the undoable class (side note: I prefer to use inner classes when implementing Memento, because they meet all the requirements of the Memento but don't break encapsulation because the inner class has a reference to the outer one's private fields).
Of course, someone has already had this idea, which Ramnivas kindly pointed out (check out Jon Tirsen's blog entries here and here). My only contribution to this discussion is the use of attributes in Java 5 to flag the undoable fields -- the rest had already been figured out. Just when you think you have a clever idea, inevitably, someone else has beat you to the punch. I do think this is a great use for Aspects, though.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment