Welcome to the home page of the com.perisic.shadow package.
This Java package implements the shadow concept known from
LPC.
Please follow this link to the newer version of Java-Shadow implementation
using the modified Jikes-compiler
The package is distributed under the
LGPL
Basically this package consists of three classes:
-
Shadowable: The common base class for all objects that can be shadowed.
-
Shadow: A base class of possible shadows.
-
ShadowException: A class for exceptions that are thrown by the call() method of a shadowable class.
When an object foo
is shadowed by a shadow bla
each message that is sent to foo
will be first received by bla
.
If bla
is able to understand the message it will continue to process it. Otherwise it passes the message further to foo
. In order to make this work all methods that are subject to shadowing have to be called via the method
call(String method Name, Object...). (Basically a call foo.call("func", arg1, arg2, ...)
is intended to be equivalent to foo.func(arg1, arg2, ...)
, but the first one can be catched by a shadow.)
Note that all other classes provided in this package are only for illustration and not necessary for the shadow concept. These are in particular:
- In com.perisic.shadow.example.lib:
NiceFellow and NiceChild.
A simple hierarchy of two shadowable classes.
- In com.perisic.shadow.example.shadows: The two example shadows
SmileShadow and
CalamityShadow.
- In com.perisic.shadow.example.mains:
- Simple: Demonstrates the use of the
call() method but does not use shadows.
- Redefine: Shows how a shadow can be used to redefine an existing method.
- Extend: Shows how a shadow can be used to extend the behaviour of a class.
A common use case with shadows is in the context of computer games where an object for a while "becomes" a different object. For instance a wizard makes a spell that transforms a human player in a black cat for certain amount of time. This is usually achieved by implementing a "cat shadow" that shadows the player object. The player object will then behave rather like a cat as determined by the shadow then a human while the shadow is on.
The preprint Approaching Inheritance from a ``Natural'' Mathematical Perspective and from a Java Driven Viewpoint: a Comparative Review links an extended version of the shadow concept to the problem of interclassing. However the syntax used there is different from the syntax implemented in this package.
Back to top
- The package has been compiled with Java 1.5. and makes use of some of Java 1.5's new features.
You might wish to install Java 1.5 from Sun.
- Download the jar-file shadow.jar
- Run the test programs:
Back to top
Feel free to ask questions or contribute ideas about this package by sending
an email to ringlist@perisic.com,
(the mailing list for the com.perisic.* packages).
You can subscribe to this list by sending an email to
ringlist-subscribe@perisic.com.
Back to top
© Marc Conrad, 2004.
The material on this page is presented "as is". There is no warranty implied by presenting this stuff.
Feel free to use the material for your own research or teaching.
When doing so please give a reference to this web site (http://perisic.com/shadow).
The package is
distributed under the terms of the LGPL
The webspace for this project is kindly provided by the Perisic
Guesthouse (www.perisic.com).
Back to top