Hi All,
I am in the process of "re-learning" Jess (after 3-4 years).
At this time, I am examining (and modifying) the "pumps" example
for the purpose of learning how JESS deals with class hierarchies and the
associated polymorphism on method calls:
(1) I have derived classes (DerivedPump / DerivedTank) from
the existing Pump / Tank classes. The only real
changes made were to the base classes were to comment out
the Thread(this).start() line in both the Tank.java and
Pump.java while in the derived classes I commented out
the attributes, called the super class in the constructor,
and added a new Thread(this).start() line. In addition,
I commented out all method calls thinking that the
"listener" interface call would make the call to the
right method (polymorphically).
(2) I am using the pumps.clp and modified the bottom part of
the file to include:
(definstance tank (bind ?tank (new DerivedTank "MAIN")))
(call (?frame getContentPane) add (?tank getComponent))
(definstance pump (bind ?pump (new DerivedPump "MAIN" ?tank)))
(call (?frame getContentPane) add (?pump getComponent))
(call (?frame getContentPane) add (new JLabel "MAIN"))
(definstance tank (bind ?tank (new DerivedTank "AUX")))
(call (?frame getContentPane) add (?tank getComponent))
(definstance pump (bind ?pump (new DerivedPump "AUX" ?tank)))
while leaving the top of the file alone, i.e.,
(defclass tank Tank extends machine)
(defclass pump Pump extends machine)
(3) The MainInJava.java was modified to include:
//Tank t = new Tank("MAIN");
DerivedTank t = new DerivedTank("MAIN");
//Pump p = new Pump("MAIN", t);
DerivedPump p = new DerivedPump("MAIN", t);
My fundamental assumption was that this code would run as is. It didn't.
Only when I changed the derived classes to include ALL the methods from
base class would it work. Small combinations of changes led it running
in some cases and in some cases it wouldn't work. ONLY when ALL methods
were included would it work correctly.
Obviously, my assumptions were wrong !!
However, my suspicion is that the "call-backs" from the "source" to
the "eventListener" will go ONLY to the level of the class hierarchy that
was registered for that particular event.
This may be trivial for a JavaBean jock, but at this time, it is a
complete mystery to me as to why it works this way.
OBTW, I do have the modified "pumps" code working as advertised - I just
don't understand the nuances.
Thanks -
Rich Halsey
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------