Sha256: 15118d4e05e0e8879f04d98338a36ab710b5d56388a85161e984ea9d63fc3e7f
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
#!/usr/bin/env ruby # Example demonstrating emerging ideas about good aspect-oriented design. Specifically, this # example follows ideas of Jonathan Aldrich on "Open Modules", where a "module" (in the generic # sense of the word...) is responsible for defining and maintaining the pointcuts that it is # willing to expose to potential aspects. Aspects are only allowed to advise the module through # the pointcut. (Enforcing this constraint is TBD) # Griswold, Sullivan, and collaborators have expanded on these ideas. See their IEEE Software, # March 2006 paper. $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib' require 'aquarium' module Aquarium class ClassWithStateAndBehavior def initialize *args @state = args p "Initializing: #{args.inspect}" end attr_accessor :state # A simpler version of the following would be # STATE_CHANGE = pointcut :method => :state STATE_CHANGE = pointcut :attribute => :state, :attribute_options => :writer end end # Observe state changes in the class, using the class-defined pointcut. observer = after :pointcut => Aquarium::ClassWithStateAndBehavior::STATE_CHANGE do |jp, *args| p "State has changed. " p " New state is #{jp.context.advised_object.state.inspect}" p " Equivalent to *args: #{args.inspect}" end object = Aquarium::ClassWithStateAndBehavior.new(:a1, :a2, :a3) object.state = [:b1, :b2]
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aquarium-0.1.0 | examples/aspect_design_example.rb |