This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-15
Channels
- # babashka (13)
- # beginners (37)
- # calva (19)
- # cider (15)
- # clj-kondo (2)
- # clojure (152)
- # clojure-norway (1)
- # clojure-sweden (10)
- # clr (5)
- # emacs (19)
- # honeysql (1)
- # introduce-yourself (19)
- # joyride (1)
- # lsp (4)
- # malli (5)
- # membrane (6)
- # off-topic (11)
- # pathom (18)
- # polylith (13)
- # practicalli (3)
- # releases (4)
- # shadow-cljs (38)
package dev.mccue.polylith.math;
import dev.mccue.polylith.math.spi.MathUtilsOps;
import java.util.ServiceLoader;
public final class MathUtils {
private static final MathUtilsOps OPS = ServiceLoader.load(MathUtilsOps.class)
.findFirst()
.orElseThrow();
private MathUtils() {}
public static int add(int a, int b) {
return OPS.add(a, b);
}
}
Make an interface to delegate topackage dev.mccue.polylith.math.spi;
public interface MathUtilsOps {
int add(int a, int b);
}
module jolly.math {
exports dev.mccue.polylith.math;
exports dev.mccue.polylith.math.spi to jolly.math.impl;
requires transitive java.sql;
uses dev.mccue.polylith.math.spi.MathUtilsOps;
}
Don't expose the interface - keep it in its own package and expose it to implementationspackage dev.mccue.polylith.math.impl;
import dev.mccue.polylith.math.spi.MathUtilsOps;
public final class MathUtilsOpsImpl implements MathUtilsOps {
@Override
public int add(int a, int b) {
return a + b;
}
}
module jolly.math.impl {
requires jolly.math;
provides dev.mccue.polylith.math.spi.MathUtilsOps
with dev.mccue.polylith.math.impl.MathUtilsOpsImpl;
}
Provide implementation of interface, which is then exported as static methods to the consumeri.e that the component modules provide a service, that interface modules require the same services that the component module provides, and that every interface module has a matching component module, and every project requires both the interface and implementation
Hi @U3JH98J4R! This looks interesting, thanks for sharing it with us! Have you considered any approaches that would let you build projects at compile-time (rather than run-time), as that would more closely match the approach we take with the Clojure version? I created this https://github.com/polyfy/polylith/issues/278 and my plan is to implement a short example in Java that shows what I mean.
Okay. I will come back to you when I have something to show.
Hi @U3JH98J4R. I found the old example that I posted in the https://github.com/polyfy/polylith/issues/278.
@U1G0HH87L left a question