Abstract type: Difference between revisions

Content added Content deleted
No edit summary
(Added Logtalk example)
Line 568: Line 568:
int add(int a, int b);
int add(int a, int b);
}</lang>
}</lang>

=={{header|Logtalk}}==
In Logtalk, methods (predicates) must be declared but their definition is not mandatory. Being a logic-based language and making use of the closed-world assumption, invoking a method that is declared but not defined simply fails. If necessary, is trivial to define a method such that it throws an exception. Moreover, Logtalk doesn't define an "abstract" or "virtual" keyword. Instead it uses an operational definition where e.g. a class is considered abstract if it doesn't provide a method for creating new instances.

Logtalk supports the definition of interfaces (protocols), which can contain public, protected, and private declarations of methods (predicates). In addition, an object can qualify an implements relation with an interface (protocol) using the keywords "public", "protected", and "private".
<lang logtalk>
:- protocol(datep).

:- public(today/3).
:- public(leap_year/1).
:- public(name_of_day/3).
:- public(name_of_month/3).
:- public(days_in_month/3).

:- end_protocol.
</lang>


=={{header|Lua}}==
=={{header|Lua}}==