com.perisic.shadow.example.mains
Class Extend
java.lang.Object
com.perisic.shadow.example.mains.Extend
- public class Extend
- extends java.lang.Object
This example shows how a shadow can be used to
to extend the functionality of a class. The class
NiceFellow is shadowed by a CalamityShadow providing
extra behaviour (tell calamity, crying). Note that the
shadow also applies to the child NiceChild of NiceFellow.
In addition we have shadowed the fabian object by a SmileShadow.
Note that the SmileShadow has no effect on Tomislav's behaviour.
This is the (uncommented) code of this class:
public class Extend {
public static void main(String [] args) {
NiceFellow.addShadow(NiceFellow.class, CalamityShadow.class);
NiceFellow fabian = new NiceFellow("Fabian");
NiceChild tomislav = new NiceChild("Tomislav");
fabian.addShadow(new SmileShadow());
fabian.call("smile",1);
fabian.call("printMood");
tomislav.call("printMood");
System.out.println("");
fabian.call("tellJokeTo", tomislav );
tomislav.printMood();
fabian.call("tellCalamityTo", tomislav );
fabian.call("cry");
tomislav.printMood();
}
- First version: 16.03.2004
-
Copyright: (c) Marc Conrad, 2004
-
See http://perisic.com/shadow for information about this package.
- The com.perisic.shadow library is distributed under the terms of the
GNU Lesser General Public License (LGPL).
- If you require the package under a different licence please contact me.
- disclaimer: The classes are provided "as is".
There is no warranty implied by using the com.perisic.shadow package.
- Note: This class needs Java 1.5 for succesfull compilation. Compile this
class with the command javac -source 1.5
Method Summary |
static void |
main(java.lang.String[] args)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Extend
public Extend()
main
public static void main(java.lang.String[] args)