- Playing with `opens` and `open` modules
- Added a service interface, implementation and client usage example
This commit is contained in:
Tristan B. Velloza Kildaire 2023-10-12 08:48:32 +02:00
parent dfd6f3af05
commit 9b64b6869a
5 changed files with 36 additions and 0 deletions

View File

@ -2,4 +2,9 @@ module ocp.hello
{
exports ocp.practice.modules.Modules;
requires transitive ocp.gendering;
opens ocp.practice.modules.Modules;
provides ocp.practice.modules.Modules.IDoable
with ocp.practice.modules.Modules.DoableImpl;
}

View File

@ -0,0 +1,12 @@
package ocp.practice.modules.Modules;
public class DoableImpl implements IDoable
{
@Override
public void doTing()
{
System.out.println("I am doing da thang");
}
}

View File

@ -0,0 +1,6 @@
package ocp.practice.modules.Modules;
public interface IDoable
{
public void doTing();
}

View File

@ -1,4 +1,6 @@
module ocp.practice.using
{
requires ocp.hello;
uses ocp.practice.modules.Modules.IDoable;
}

View File

@ -1,7 +1,12 @@
package ocp.practice.using.Greeting;
import ocp.practice.modules.Modules.Hello;
import java.util.Iterator;
import java.util.ServiceLoader;
import ocp.gendering.gendering.Gender;
import ocp.practice.modules.Modules.IDoable;
/**
* Modules
@ -16,5 +21,11 @@ public class Greeter
Hello.hello("Bobby!");
Gender gender = Hello.getGender();
System.out.println("Gender is: "+gender);
Iterable<IDoable> services = ServiceLoader.load(IDoable.class);
for(IDoable service: services)
{
service.doTing();
}
}
}