Include Paulo Moura's Logtalk OO LP system
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@53 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
16
Logtalk/examples/inheritance/NOTES
Normal file
16
Logtalk/examples/inheritance/NOTES
Normal file
@@ -0,0 +1,16 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.8.4
|
||||
|
||||
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
|
||||
To load all objects in this example consult the inheritance.loader utility
|
||||
file (note that the *.loader files are Prolog files).
|
||||
|
||||
This folder contains examples of public, protected and private inheritance,
|
||||
for both prototypes and classes/instances. The category "predicates" defines
|
||||
a set of three predicates, one public, one protected and one private. This
|
||||
category is imported by the root objects: "parent" for the prototypes and
|
||||
"object" for the classes/instances. Each root object have a set of three
|
||||
descendants, each one using one of the inheritance types.
|
98
Logtalk/examples/inheritance/SCRIPT
Normal file
98
Logtalk/examples/inheritance/SCRIPT
Normal file
@@ -0,0 +1,98 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.8.4
|
||||
|
||||
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
|
||||
|
||||
|
||||
% parent interface
|
||||
|
||||
| ?- parent::interface.
|
||||
|
||||
public/0 - public
|
||||
protected/0 - protected
|
||||
private/0 - private
|
||||
interface/0 - public
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% prototype1 extends public::parent
|
||||
|
||||
| ?- prototype1::interface.
|
||||
|
||||
interface/0 - public
|
||||
public/0 - public
|
||||
protected/0 - protected
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% prototype2 extends protected::parent
|
||||
|
||||
| ?- prototype2::interface.
|
||||
|
||||
interface/0 - public
|
||||
public/0 - protected
|
||||
protected/0 - protected
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% prototype3 extends private::parent
|
||||
|
||||
| ?- prototype3::interface.
|
||||
|
||||
interface/0 - public
|
||||
public/0 - private
|
||||
protected/0 - private
|
||||
|
||||
yes
|
||||
|
||||
|
||||
|
||||
% object (root of the inheritance graph) interface
|
||||
|
||||
| ?- root::interface.
|
||||
|
||||
public/0 - public
|
||||
protected/0 - protected
|
||||
private/0 - private
|
||||
interface/0 - public
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% instance1 instantiates subclass1 that specializes public::root
|
||||
|
||||
| ?- instance1::interface.
|
||||
|
||||
interface/0 - public
|
||||
public/0 - public
|
||||
protected/0 - protected
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% instance2 instantiates subclass2 that specializes protected::root
|
||||
|
||||
| ?- instance2::interface.
|
||||
|
||||
interface/0 - public
|
||||
public/0 - protected
|
||||
protected/0 - protected
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% instance3 instantiates subclass3 that specializes private::root
|
||||
|
||||
| ?- instance3::interface.
|
||||
|
||||
interface/0 - public
|
||||
public/0 - private
|
||||
protected/0 - private
|
||||
|
||||
yes
|
18
Logtalk/examples/inheritance/inheritance.loader
Normal file
18
Logtalk/examples/inheritance/inheritance.loader
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([
|
||||
predicates,
|
||||
interface,
|
||||
|
||||
parent,
|
||||
prototype1,
|
||||
prototype2,
|
||||
prototype3,
|
||||
|
||||
root,
|
||||
subclass1,
|
||||
subclass2,
|
||||
subclass3,
|
||||
instance1,
|
||||
instance2,
|
||||
instance3])).
|
6
Logtalk/examples/inheritance/instance1.lgt
Normal file
6
Logtalk/examples/inheritance/instance1.lgt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
:- object(instance1,
|
||||
instantiates(subclass1)).
|
||||
|
||||
|
||||
:- end_object.
|
6
Logtalk/examples/inheritance/instance2.lgt
Normal file
6
Logtalk/examples/inheritance/instance2.lgt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
:- object(instance2,
|
||||
instantiates(subclass2)).
|
||||
|
||||
|
||||
:- end_object.
|
6
Logtalk/examples/inheritance/instance3.lgt
Normal file
6
Logtalk/examples/inheritance/instance3.lgt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
:- object(instance3,
|
||||
instantiates(subclass3)).
|
||||
|
||||
|
||||
:- end_object.
|
22
Logtalk/examples/inheritance/interface.lgt
Normal file
22
Logtalk/examples/inheritance/interface.lgt
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
:- category(interface).
|
||||
|
||||
|
||||
:- public(interface/0).
|
||||
:- mode(interface, one).
|
||||
|
||||
|
||||
interface :-
|
||||
forall(
|
||||
(::current_predicate(Functor/Arity),
|
||||
functor(Pred, Functor, Arity)),
|
||||
(::predicate_property(Pred, Prop), scope(Prop),
|
||||
writeq(Functor/Arity), write(' - '), writeq(Prop), nl)).
|
||||
|
||||
|
||||
scope(public).
|
||||
scope(protected).
|
||||
scope(private).
|
||||
|
||||
|
||||
:- end_category.
|
6
Logtalk/examples/inheritance/parent.lgt
Normal file
6
Logtalk/examples/inheritance/parent.lgt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
:- object(parent,
|
||||
imports(predicates, interface)).
|
||||
|
||||
|
||||
:- end_object.
|
25
Logtalk/examples/inheritance/predicates.lgt
Normal file
25
Logtalk/examples/inheritance/predicates.lgt
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
:- category(predicates).
|
||||
|
||||
|
||||
:- public(public/0).
|
||||
:- mode(public, one).
|
||||
|
||||
:- protected(protected/0).
|
||||
:- mode(protected, one).
|
||||
|
||||
:- private(private/0).
|
||||
:- mode(private, one).
|
||||
|
||||
|
||||
public :-
|
||||
write('Public predicate declared and defined in category predicates.'), nl.
|
||||
|
||||
protected :-
|
||||
write('Protected predicate declared and defined in category predicates.'), nl.
|
||||
|
||||
private :-
|
||||
write('Private predicate declared and defined in category predicates.'), nl.
|
||||
|
||||
|
||||
:- end_category.
|
7
Logtalk/examples/inheritance/prototype1.lgt
Normal file
7
Logtalk/examples/inheritance/prototype1.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(prototype1,
|
||||
imports(interface),
|
||||
extends(public::parent)).
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/inheritance/prototype2.lgt
Normal file
7
Logtalk/examples/inheritance/prototype2.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(prototype2,
|
||||
imports(interface),
|
||||
extends(protected::parent)).
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/inheritance/prototype3.lgt
Normal file
7
Logtalk/examples/inheritance/prototype3.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(prototype3,
|
||||
imports(interface),
|
||||
extends(private::parent)).
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/inheritance/root.lgt
Normal file
7
Logtalk/examples/inheritance/root.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(root,
|
||||
imports(predicates, interface),
|
||||
instantiates(root)).
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/inheritance/subclass1.lgt
Normal file
7
Logtalk/examples/inheritance/subclass1.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(subclass1,
|
||||
imports(interface),
|
||||
specializes(public::root)).
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/inheritance/subclass2.lgt
Normal file
7
Logtalk/examples/inheritance/subclass2.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(subclass2,
|
||||
imports(interface),
|
||||
specializes(protected::root)).
|
||||
|
||||
|
||||
:- end_object.
|
7
Logtalk/examples/inheritance/subclass3.lgt
Normal file
7
Logtalk/examples/inheritance/subclass3.lgt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
:- object(subclass3,
|
||||
imports(interface),
|
||||
specializes(private::root)).
|
||||
|
||||
|
||||
:- end_object.
|
Reference in New Issue
Block a user