Facts Inheritance

Discussions related to Visual Prolog
vjoer
Active Member
Posts: 29
Joined: 7 Feb 2006 13:42

Facts Inheritance

Unread post by vjoer » 4 Feb 2013 20:40

Hello

I have tried to create parent and child classes using inheritance. I assumed that the facts are also inherited in the child class together with the predicates. I was surprised that the facts did not seem to be inherited.
Would you please clarify this.

Thanks
Viorel Farcas

User avatar
Thomas Linder Puls
VIP Member
Posts: 1634
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 6 Feb 2013 23:25

The object system is described in the language reference.
If class B inherits from class C, then a B object will contain a C object. So a B object will contain all the facts that a C object does. But the facts are just as invisible to the B object than to "anybody" else: those facts are owned by the embedded C object.
Regards Thomas Linder Puls
PDC

vjoer
Active Member
Posts: 29
Joined: 7 Feb 2006 13:42

Unread post by vjoer » 7 Feb 2013 6:36

Hello Thomas

I managed to understand finally. The facts are accessible via get/set methods on the C class as you mentioned.

Thanks
Viorel Farcas

User avatar
Thomas Linder Puls
VIP Member
Posts: 1634
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 7 Feb 2013 9:56

Yes, if you create such accessor predicates. I will however suggest using properties instead of get/set predicates.

And in any case, you should only make them public if it makes sense.
Regards Thomas Linder Puls
PDC

Post Reply