[3665] in java-interest

home help back first fref pref prev next nref lref last post

Class Casting and Dynamic Loading.

daemon@ATHENA.MIT.EDU (Bindu Wavell (RUFUS))
Tue Nov 21 21:02:12 1995

To: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
cc: java-interest@java.sun.com
Date: Tue, 21 Nov 1995 13:06:52 -0700
From: Bindu Wavell (RUFUS) <wavell@taussky.cs.colorado.edu>


I'm writing a _bunch_ of algorithm demos for java. These will be like the
sort demos that come with java, but will go a bunch further, allowing the
user to load different types of data, and change data in the middle of 
algorithm execution. I created a simple sorting algorithm engine, and am
now trying to generalize it so that it can dynamically load the algorithm
object, and the data structure object (used by the algorithm). 

I have dynamic loading working for sorting algorithms. i.e. I have a sorting 
engine that looks in the html file for a pointer/parameter to an algorithm and 
then instanciates that sort. 

What I would like to do is this: I would like to have a main class: CNDemo
that is derived from applet. When this starts it will create a new CNAlgorithm
dynamically (the interface to this is generic and works already). I would also
like to create a CNDataStructure dynamically. This would either use getParam
or a method call into the CNAlgorithm to get the data structure class name.
Once the CNDataStructure is created it needs to be passed to the CNAlgorithm.
This all works, however this is the difficulty. The CNAlgorithm needs the 
CNDataStructure to be a fully functioanl descendant of CNDataStructure (i.e.
CNArrayDataStructure) and needs to be able to access methods that are
specific to the full class.

Here is my problem: CNDemo creates an object, which it thinks is a 
CNDataStructure, but that is actually _descended_ from CNDataStructure.
When this is passed to the descendant of CNAlgorithm, it does not seam
to be possible to cast it back to a Descendant of CNDataStrucutre, so I
can't access the data-structure specific methods.

Any ideas would be greatly appreciated :)

TIA, Bindu

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post