I played around with an example in Java. You will use the same workspace structure as in Clojure. In Clojure you can put your functions directly in the namespace, e.g. com.mycompany.mycomponent.interface. But in Java, you need to create public static methods in a corresponding component class to achieve the same thing. Java doesn't support aliases in imports, but a workaround is to name the interface classes like com.mycompany.mycomponent.Mycomponent which allows you to import it from other components and refer to them with Mycomponent.myfunction(). Here is an example using the components User and Address:
Directory/file structure:
myworkspace
components
user
src
com
mycompany
User // the 'User' interface (Java class)
Core // the 'User' implementation (Java class)
address
src
com
mycompany
Address // the 'Address' interface (Java class)
Core // the 'Address' implementation (Java class)
Address (interface)
package com.mycompany.address;
import com.mycompany.address.Core;
public class Address {
public static String street() {
// delegates to the implementation.
return Core.street();
}
}
Address (implementation)
package com.mycompany.address;
public class Core {
public static String street () {
// the actual implementation.
return "My street";
}
}
User (interface)
package com.mycompany.user;
import com.mycompany.user.Core;
public class User {
public static void yourStreet() {
// delegate to the implementation.
Core.yourStreet();
}
}
User (implementation)
package com.mycompany.user;
import com.mycompany.address.Address;
public class Core {
public static void yourStreet() {
// Notice that we can access the 'address' component by using it's interface name!
String street = Address.street();
System.out.println("Your street is:" + street);
}
}
If you have several components that implement the same interface, e.g. an 'Admin' and a 'User' component, that both implements the 'User' interface, then the workspace file structure could look like this:
myworkspace
components
admin
src
com
mycompany
user
User
Core
user
src
com
mycompany
user
User
Core
Notice that the name of the interfaces is the same in the two components, com.mycompany.user.User. This is also how it's done in Clojure, but with the difference that in Clojure the interface will get the name com.mycompany.user.interface and be imported with the 'user' alias (when used, in this example).