objectspacevisitor.rb

Path: lib/mues/objectspacevisitor.rb  (CVS)
Last Update: Sat Aug 18 22:54:10 -0700 2007

This file contains the MUES::ObjectSpaceVisitor class: A simple no-op objectspace visitor superclass that is used by visitor classes that traverse an objectspace for MUES subsystems such as MUES::ObjectStore::MemoryManager objects.

This is designed to be used in the following fashion: subclass this class for each of the object behaviors you wish to implement, appending ‘Visitor’ to the behavior name, i.e. MethodNameVisitor < MUES::ObjectSpaceVisitor. Then, for each type of object to be able to exhibit this behavior, define a method on the subclassed visitor named ‘visitClassName’ that accepts an object. This should then be used to enact the desired behavior on said object. Finally, all objects that deem themselves capable of being visited must define a method on themselves accept, which accepts one argument (a visitor object), and calls the visit method on that visitor with it‘s self as the argument. This can also be a call the the visitClassName method, if you want to skip a step (but then YOU will have to change that if you ever change the class‘s name, or subclass that class so as to break its ability to be treated as a ClassName object!).

Synopsis

  class Foo
      def accept( visitor )
          visitor.visit(self)
      end
      def myMethod
          return 42
      end
  end

  class Bar < Foo
      def myMethodEmulator
          return 6 * 7
      end
  end

  class MyMethodVisitor < MUES::ObjectSpaceVisitor
      def visitFooClass( foo )
          foo.myMethod()
      end
      def visitBarClass( bar )
          bar.myMethodEmulator()
      end
  end

  f = Foo.new
  b = Bar.new
  v = MyMethodVisitor.new

  puts "life is what life does" if
      f.accept(v) == b.accept(v)

Subversion ID

$Id: objectspacevisitor.rb 1206 2004-05-09 21:25:11Z deveiant $

Authors

  • Michael Granger <ged@FaerieMUD.org>
  • Martin Chase <stillflame@FaerieMUD.org>

Copyright

Copyright (c) 2000-2003 The FaerieMUD Consortium. All rights reserved.

This module is free software. You may use, modify, and/or redistribute this software under the terms of the Perl Artistic License. (See language.perl.com/misc/Artistic.html)

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Required files

mues/object   mues/mixins  

[Validate]