mirror of https://github.com/deavmi/JavaOCP
Modules
- Playing with `opens` and `open` modules - Added a service interface, implementation and client usage example
This commit is contained in:
parent
dfd6f3af05
commit
9b64b6869a
|
@ -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;
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package ocp.practice.modules.Modules;
|
||||
|
||||
public interface IDoable
|
||||
{
|
||||
public void doTing();
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
module ocp.practice.using
|
||||
{
|
||||
requires ocp.hello;
|
||||
|
||||
uses ocp.practice.modules.Modules.IDoable;
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue