One of the easiest ways to understand Clprolf class roles is to look at wrappers of well-known Java classes.
By re-expressing familiar components like Socket
, Scanner
, or System
, we can immediately see how Clprolf’s declensions clarify their nature and responsibility.
Each wrapper highlights a specific situation: abstract concepts, expert components, active agents, or static utilities.
This makes wrappers both practical (they can replace Java classes through polymorphism) and educational (they illustrate how to apply Clprolf roles consistently).
A project exists in the Clprolf sources, under the package clprolf.wrappers.java
.
It shows concrete examples of class roles, by writing wrappers for the Java Standard Library.
Thanks to polymorphism, these wrappers can directly replace the equivalent Java classes or interfaces. They also serve as educational examples of how to apply Clprolf declensions.
Here, ClpSocket
is declared as an @Abstraction
.
Since inheritance from Java classes is not natural in Clprolf, we use @Forced_inh
.
We choose Abstraction because a socket is an abstract system concept. Equivalent roles could work, but abstraction fits best.
package clprolf.wrappers.java.net;
import java.net.Socket;
import org.simol.simolframework.java.Abstraction;
import org.simol.simolframework.java.Forced_inh;
import org.simol.simolframework.java.Nature;
@Forced_inh // Not allowed except with this
@Abstraction
public class ClpSocket extends @Nature Socket {
}
Here, the name is slightly adapted: SocketServer
instead of Java’s ServerSocket
.
We declare it as @Agent(Gender.EXPERT_COMPONENT)
because it is an expert component for serving sockets.
package clprolf.wrappers.java.net;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import org.simol.simolframework.java.Forced_inh;
import org.simol.simolframework.java.Nature;
import org.simol.simolframework.java.Role;
import org.simol.simolframework.java.Agent;
@Forced_inh
@Agent(Gender.EXPERT_COMPONENT)
public class ClpSocketServer extends @Nature ServerSocket {
public ClpSocketServer() throws IOException {
super();
}
public ClpSocketServer(int port) throws IOException {
super(port);
}
public ClpSocketServer(int port, int backlog) throws IOException {
super(port, backlog);
}
public ClpSocketServer(int port, int backlog, InetAddress bindAddr) throws IOException {
super(port, backlog, bindAddr);
}
}
For JButton
, it is natural to use @Abstraction
.
package clprolf.wrappers.javax.swing;
import javax.swing.JButton;
import org.simol.simolframework.java.Forced_inh;
import org.simol.simolframework.java.Abstraction;
import org.simol.simolframework.java.Role;
@Forced_inh
@Abstraction
public class ClpJButton extends @Nature JButton {
}
ClpScanner
shows that even system abstractions can be modeled as @Agent
.
It plays an active role in applications — scanning is its autonomous responsibility.
We don’t need to add EXPERT_COMPONENT
here, as Agent
is already explicit enough.
package clprolf.wrappers.java.util;
import java.util.Scanner;
import org.simol.simolframework.java.Agent;
@Agent
public final class ClpScanner { // Java Scanner is final, so we use composition
private final Scanner internal;
public ClpScanner(Scanner javaScanner) {
this.internal = javaScanner;
}
public String nextLine() {
return this.internal.nextLine();
}
}
System
is unusual:
final
.This makes it a perfect fit for @Abstraction(Gender.STATIC)
.
We see it as a singleton abstraction of the operating system.
package clprolf.wrappers.java.lang;
import java.io.Console;
import java.io.InputStream;
import java.io.PrintStream;
import org.simol.simolframework.java.Abstraction;
import org.simol.simolframework.java.Role;
@Abstraction(Gender.STATIC)
public final class ClpSystem {
public static final PrintStream getOut() {
return System.out;
}
public static final InputStream getIn() {
return System.in;
}
public static final PrintStream getErr() {
return System.err;
}
public static Console console() {
return System.console();
}
}
String
is also final
, so the wrapper must use composition.
Here, the class is an abstraction of the concept → @Abstraction
.
package clprolf.wrappers.java.lang;
import org.simol.simolframework.java.Abstraction;
import org.simol.simolframework.java.Role;
@Abstraction
public final class ClpString {
private final String internal;
public ClpString(String internalString) {
this.internal = internalString;
}
public String getInternal() {
return internal;
}
// Static methods belong to the static aspect
public static String valueOf(int i) {
return String.valueOf(i);
}
}
Clprolf wrappers are both useful and educational:
👉 Wrappers fill the gap between the Java world and the Clprolf world!