Thanks, that definitely helps.  The following seems to do what I want:
 
r.eval("(defclass IInterface1 IInterface1)");
r.eval("(defclass IInterface2 IInterface2 extends IInterface1)");
r.eval("(defclass AbstractClassA AbstractClassA extends IInterface2)");
r.eval("(defclass ClassB ClassB extends AbstractClassA)");
r.eval("(defclass ClassC ClassC extends AbstractClassA)");
r.eval("(defclass ClassD ClassD extends IInterface2)");

Now, if I want to test for any of the 3 concrete classes, I can use
?x <- (IInterface2 (name ?name))

If I want to limit to just B or C, I can use

?y <- (AbstractClassA (name ?name))

 
-Russ
________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Wolfgang Laun
Sent: Sunday, May 18, 2008 3:09 PM
To: [email protected]
Subject: Re: JESS: Classes and Interfaces


It is not possible to refer to an interface in the from-class clause of
a deftemplate.
 
A class hierarchy including an abstract class can be mirrored as shown
below.

(deftemplate ClassA (declare (from-class AbstractClassA)))
(deftemplate ClassB extends ClassA (declare  (from-class ClassB)))
(deftemplate ClassC extends ClassA (declare  (from-class ClassC)))

(defrule findA
  ?x <- (ClassA (name ?name))
  =>
  (printout t "Found a ClassA called " ?name crlf))

(defrule findB
  ?x <- (ClassB (name ?name))
  =>
  (printout t "Found a ClassB called " ?name crlf))

(defrule findC
  ?x <- (ClassC (name ?name))
  =>
  (printout t "Found a ClassC called " ?name crlf))

(reset)
(add (new ClassB "objB1" "B1" ))
(add (new ClassC "objC1" "C1" ))
(facts)
(run)

Both facts are matched by the findA rule as well:

f-0   (MAIN::initial-fact)
f-1   (MAIN::ClassB (class <Java-Object:java.lang.Class>) (name "objB1")
(value "B1") (OBJECT <Java-Object:play.ClassB>))
f-2   (MAIN::ClassC (class <Java-Object:java.lang.Class>) (name "objC1")
(value "C1") (OBJECT <Java-Object:play.ClassC>))
For a total of 3 facts in module MAIN.
Found a ClassC called objC1
Found a ClassA called objC1
Found a ClassB called objB1
Found a ClassA called objB1
4

Kind regards

Wolfgang

On 5/18/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: 

        I have the following class structure
        
        IInterface1
               getName()
           IInterface2 extends IInterface1
               getValue()
        
        AbstractClassA implements IInterface2
               ClassB extends AbstractClassA,
               ClassC extends AbstractClassA
        
        ClassD implements IInterface2
        
        All 3 concrete classes implement IInterface2 and expose
"getName".
        
        I'd like to write a Rule that matches a fact of any of the 3
concrete
        classes (B, C, and D).  I use the defclass construct for the
various
        types and interfaces and add 3 facts, one of each of the 3
concrete
        classes.
        
        Two issues arise:
        
        First, when I try the following rule:
               ?x <- (IInterface2 (name ?name)) => (printout t \"Found
an
        IInterface2 called \" ?name crlf)
        "Message: No such slot name in template MAIN::Interface2 at
token
        'name'."  I only get this error on IInterface2.
        
        If I write comparable rules for all of the types and run them,
only the
        rules matching the concrete classes match.  E.g.
        ?x <- (AbstractClassA (name ?x_name) (OBJECT ?x_obj)) does not
match but
        ?x <- (ClassB (name ?x_name) (OBJECT ?x_obj)) does (only the one
        instance of course).
        
        What's the best way handle this type of situation? I can send a
zip with
        sample code if that helps. Thanks.
        
        -Russ
        
        
        
        
        
        
        
        
        
--------------------------------------------------------------------
        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]
        
--------------------------------------------------------------------
        
        




--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to