THE CLPROLF PROGRAMMING LANGUAGE


Interfaces in Clprolf — Complete Overview

1. General Principles

In Clprolf, an interface is always a contract. This applies both to versions (different implementations of the same concept) and to capacities (common abilities across versions).


2. Compatibility Interfaces

An interface in Clprolf is called a compatibility interface. Its purpose is to guarantee that an object is compatible with a certain contract.

When we declare a variable of an interface type, we are not binding it to a specific class — only to the compatibility defined by that interface.


with_compat

Whenever a variable, parameter, or field uses an interface type, it must be preceded by with_compat (or @With_compat in the framework). This marks the point of loose coupling.

Exception: method return types do not require with_compat.

@With_compat UserDAO dao;

contracts

The Java keyword implements is replaced by contracts. A class lists all the contracts (interfaces) it fulfills. In the framework, use @Contracts.

public class UserDAOImpl implements @Contracts UserDAO {
    public User getUser(int id) { /* … */ }
}

3. Capacity Interfaces

A capacity interface describes an ability (an “-able” trait), such as Comparable. It extends other interfaces but cannot be implemented directly by a class. This prevents confusion between versions and capacities.

A version interface that extends a capacity must also declare a class role consistent with the advice.

Example: a Car interface extending ClpComparable<Car> and a CarClass that contracts it.


4. Version Interfaces

A version interface defines the abstraction for multiple concrete implementations. It corresponds to the usual case of loose coupling in Java.

@Compat_interf_version
public interface ClpConnection extends Connection {
    void close() throws SQLException;
}

@Abstraction
public class MyAwesomeDatabaseConnection implements @Contracts ClpConnection {
    public void close() throws SQLException { /* … */ }
}

5. Generic compat_interf

The keyword compat_interf is a generic fallback. It defines an interface without a declared role. Not recommended, but sometimes useful.

public compat_interf MyMysteriousInterface {
    void myStrangeJob(String param);
}

6. Inheritance Rules and @Forced_int_inh

Clprolf enforces simple and intuitive rules:

Violations can be bypassed explicitly with @Forced_int_inh, which forces interface inheritance (on a class, an interface, or a specific contract type).


7. Features for Interface Inheritance

Clprolf also provides optional features to treat interfaces as if they were abstract classes:

This makes interfaces behave like full abstract hierarchies, enabling strong loose coupling in collaborative projects.

Example (language)

public version_inh agent Animal {
    void eat(String foodName);
}

public version_inh agent Dog nature Animal {
    void bark(int duration);
}

public agent AnimalImpl contracts Animal { … }
public agent DogImpl nature AnimalImpl contracts Dog { … }

Example (framework)

@Agent
@Version_inh
public interface Animal {
    void eat(String foodName);
}

@Agent
@Version_inh
public interface Dog extends @Nature Animal {
    void bark(int duration);
}

8. Conclusion

Interfaces in Clprolf are always about compatibility:

This approach keeps design clear, consistent, and role-driven, while preserving loose coupling.