Call "abstract" method of Subclass

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
rbt
Posts: 17
Joined: Tue Feb 09, 2010 10:21 am

Call "abstract" method of Subclass

Post by rbt » Mon Feb 15, 2010 9:19 am

As a java programmer I'am used to calling abstract methods, that are implemented by subclasses.
Is that not possible in logtalk?

Look at the following example:

Code: Select all

:- object(root).

    :- public(foo/1).
    :- public(abstract/1).
    
    foo(X):-
        abstract(X).
    
:- end_object.


:- object(descendant,
    extends(root)).
    :- public(abstract/1).

    abstract(descendant).

:- end_object.
If i now call:

Code: Select all

descendant::(foo(Bar)).
false.
I expected another result. How to implemented the desired behaviour with logtalk?

Best.

rbt

Paulo Moura
Logtalk developer
Posts: 474
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Call "abstract" method of Subclass

Post by Paulo Moura » Mon Feb 15, 2010 12:11 pm

In "root", you need to send the message abstract/1 to self, instead of calling it directly. I.e. write:

Code: Select all

    foo(X):-
        ::abstract(X).
There is no need to repeat the public/1 directive in "descendant"; the scope declaration is inherited. In your original code, the query is false instead of resulting in an error because of the implicit closed-world assumption: predicates declared but not defined are implicitly false.

Please note that, in Logtalk, the "keyword" "extends" declares a relation between a prototype and its parent, not a relation between classes. For superclass-subclass relations and class-instance relations, Logtalk uses, respectively, the "keywords" "specializes" and "instantiates".

Happy logtalking,

Paulo
Paulo Moura
Logtalk developer

rbt
Posts: 17
Joined: Tue Feb 09, 2010 10:21 am

Re: Call "abstract" method of Subclass

Post by rbt » Tue Feb 16, 2010 9:10 pm

Paulo Moura wrote:In "root", you need to send the message abstract/1 to self, instead of calling it directly. I.e. write:

Code: Select all

    foo(X):-
        ::abstract(X).
There is no need to repeat the public/1 directive in "descendant"; the scope declaration is inherited. In your original code, the query is false instead of resulting in an error because of the implicit closed-world assumption: predicates declared but not defined are implicitly false.

Please note that, in Logtalk, the "keyword" "extends" declares a relation between a prototype and its parent, not a relation between classes. For superclass-subclass relations and class-instance relations, Logtalk uses, respectively, the "keywords" "specializes" and "instantiates".
[...]
Thank you very much for your fast and competent feedback.

rbt

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest