Does the order of delegating interfaces to facts matter? And if so, why is it not the case for inheritance? I ask these questions because my program behaved unexpectedly when I used delegation rather than inheritance and I could not figure out a very logical explanation for this.
In the sample below, I have an interface, called fruit, that supports two other interfaces, male and female, which in turn supports a third interface, sex. I have implemented the fruit interface using 3 different ways:
(1) By delegation, where the compiler reports no errors (except for the warning that male and female facts are not used)
(2) By inheritance, and the compile returns a very helpful message: An ambiguous inheritance of the predicate or property definition sex::name (i)' in the class 'fruit' (from classes 'male' and 'female')
(3) By inheritance using the error message in 2 to help me make a rational decision about how a fruit should behave.
Code: Select all
interface sex
properties
name:string.
end interface
class sex:sex end class
implement sex
facts
name:string:=class_name().
end implement
/********************************************/
interface male supports sex
end interface male
class male:male end class
implement male inherits sex
end implement
/********************************************/
interface female supports sex
end interface
class female:female end class
implement female inherits sex
end implement
/********************************************/
interface fruit supports male, female
constants
version:integer = 2.
end interface
class fruit:fruit end class
#if fruit::version=1 #then
implement fruit
facts
male:male:=erroneous.
female:female:=erroneous.
delegate interface male to male
delegate interface female to female
end implement fruit
#endif
#if fruit::version=2 #then
implement fruit inherits male, female
end implement fruit
#endif
#if fruit::version=3 #then
implement fruit inherits male, female
resolve interface sex from male
end implement fruit
#endif
/********************************************/
goal
succeed().