Merge pull request #6975 from alejandrogervasio/decouplingpattern1

BAEL-2946 - Module Decoupling Pattern 1
This commit is contained in:
Erik Pragt 2019-05-20 22:35:38 +10:00 committed by GitHub
commit 1ce539f233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>consumermodule</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<parent>
<groupId>com.baeldung.decoupling-pattern1</groupId>
<artifactId>decoupling-pattern1</artifactId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package com.baeldung.consumermodule;
import com.baeldung.servicemodule.external.TextService;
import com.baeldung.servicemodule.external.TextServiceFactory;
public class Application {
public static void main(String args[]) {
TextService textService = TextServiceFactory.getTextService("lowercase");
System.out.println(textService.processText("Hello from Baeldung!"));
}
}

View File

@ -0,0 +1,3 @@
module com.baeldung.consumermodule {
requires com.baeldung.servicemodule;
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.decoupling-pattern1</groupId>
<artifactId>decoupling-pattern1</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>servicemodule</module>
<module>consumermodule</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.servicemodule</groupId>
<artifactId>servicemodule</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung.decoupling-pattern1</groupId>
<artifactId>decoupling-pattern1</artifactId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,7 @@
package com.baeldung.servicemodule.external;
public interface TextService {
String processText(String text);
}

View File

@ -0,0 +1,14 @@
package com.baeldung.servicemodule.external;
import com.baeldung.servicemodule.internal.LowercaseTextService;
import com.baeldung.servicemodule.internal.UppercaseTextService;
public class TextServiceFactory {
private TextServiceFactory() {}
public static TextService getTextService(String name) {
return name.equalsIgnoreCase("lowercase") ? new LowercaseTextService(): new UppercaseTextService();
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.servicemodule.internal;
import com.baeldung.servicemodule.external.TextService;
public class LowercaseTextService implements TextService {
@Override
public String processText(String text) {
return text.toLowerCase();
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.servicemodule.internal;
import com.baeldung.servicemodule.external.TextService;
public class UppercaseTextService implements TextService {
@Override
public String processText(String text) {
return text.toUpperCase();
}
}

View File

@ -0,0 +1,3 @@
module com.baeldung.servicemodule {
exports com.baeldung.servicemodule.external;
}