CSC/ECE 517 Fall 2010/ch3 3d mr

From Expertiza_Wiki
Revision as of 09:16, 5 October 2010 by Mwroda (talk | contribs) (→‎AspectR)
Jump to navigation Jump to search

Aspect-oriented programming and AspectR

AspectR is a very useful Ruby module, but it is not easy to find documentation on it that is appropriate for students taking this class. Find, or construct, documentation that explains what it does without presuming previous knowledge of AspectJ, that describes many or all methods of the module and how they work. Also find or produce an easy-to-understand example that does not involve logging. Show how the example would be implemented in AspectJ and AspectR.

Overview

Motivation

Methods

Example

AspectR

 class User
  attr_accessor :name
  def initialize name
     @name = name
  end
 end

 class UserObserver < Aspect
  def new_name(method, object, exitstatus, *args)
     puts "method: #{method}"
   puts "New name: #{args[0]}"
  end
 end

 UserObserver.new.wrap(User, :new_name, nil, /name=/)
 UserObserver.new.wrap(User, :new_name, nil, /name=/)
 bob = User.new "bob"
 ted = User.new "ted"
 bob.name = "fred"
 ted.name = "ed"

AspectJ

References

External Links