Revert "Hexagonal architecture in Java"
This reverts commit 4b669dc6880a9cfb9dce1712ecf6d9637ac73259.
This commit is contained in:
parent
fa8bf51686
commit
8c8d2f3029
@ -1,3 +0,0 @@
|
|||||||
## Hexagonal Architecture
|
|
||||||
|
|
||||||
This module contains article about Hexagonal Architecture
|
|
@ -1,19 +0,0 @@
|
|||||||
<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>hcom.baeldung</groupId>
|
|
||||||
<artifactId>hexagonal-architecture-java</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<build>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.hexagonal;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.adapters.FileWriterAdapter;
|
|
||||||
import com.baeldung.hexagonal.adapters.InMemorySportsDataAdapter;
|
|
||||||
import com.baeldung.hexagonal.adapters.UserRequestAdapter;
|
|
||||||
import com.baeldung.hexagonal.ports.FetchSportsRevenue;
|
|
||||||
import com.baeldung.hexagonal.ports.UserRequest;
|
|
||||||
import com.baeldung.hexagonal.ports.WriteSportsRevenue;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
FetchSportsRevenue sportsRevenue = new InMemorySportsDataAdapter();
|
|
||||||
WriteSportsRevenue writeSportsRevenue = new FileWriterAdapter();
|
|
||||||
UserRequest userReq = new UserRequestAdapter(sportsRevenue, writeSportsRevenue);
|
|
||||||
|
|
||||||
userReq.processRequest("Football");
|
|
||||||
userReq.processRequest("Cricket");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.adapters;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.model.SportRevenue;
|
|
||||||
import com.baeldung.hexagonal.ports.WriteSportsRevenue;
|
|
||||||
|
|
||||||
public class FileWriterAdapter implements WriteSportsRevenue {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeSportsReveue(SportRevenue sportRevenue) {
|
|
||||||
try (FileWriter fw = new FileWriter(new File("revenue.txt"),true)) {
|
|
||||||
fw.write(sportRevenue.toString());
|
|
||||||
fw.write(System.lineSeparator());
|
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.adapters;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.model.SportRevenue;
|
|
||||||
import com.baeldung.hexagonal.ports.FetchSportsRevenue;
|
|
||||||
|
|
||||||
public class InMemorySportsDataAdapter implements FetchSportsRevenue {
|
|
||||||
|
|
||||||
List<SportRevenue> data;
|
|
||||||
|
|
||||||
public InMemorySportsDataAdapter() {
|
|
||||||
data = Arrays.asList(
|
|
||||||
new SportRevenue("Football",2200000),
|
|
||||||
new SportRevenue("Cricket", 1700000),
|
|
||||||
new SportRevenue("Baseball",1567000));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SportRevenue retrieveSportRevenue(String sportName) {
|
|
||||||
return data.stream()
|
|
||||||
.filter(category -> sportName.equals(category.getName()))
|
|
||||||
.findAny().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.adapters;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.core.SportsApp;
|
|
||||||
import com.baeldung.hexagonal.ports.FetchSportsRevenue;
|
|
||||||
import com.baeldung.hexagonal.ports.UserRequest;
|
|
||||||
import com.baeldung.hexagonal.ports.WriteSportsRevenue;
|
|
||||||
|
|
||||||
public class UserRequestAdapter implements UserRequest {
|
|
||||||
|
|
||||||
private SportsApp sportsApp;
|
|
||||||
|
|
||||||
public UserRequestAdapter(FetchSportsRevenue sportsRevenue, WriteSportsRevenue writeSportsRevenue) {
|
|
||||||
sportsApp = new SportsApp(sportsRevenue, writeSportsRevenue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processRequest(String sportName) {
|
|
||||||
sportsApp.fetchAndWrite(sportName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.core;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.model.SportRevenue;
|
|
||||||
import com.baeldung.hexagonal.ports.FetchSportsRevenue;
|
|
||||||
import com.baeldung.hexagonal.ports.WriteSportsRevenue;
|
|
||||||
|
|
||||||
public class SportsApp {
|
|
||||||
|
|
||||||
private FetchSportsRevenue sportsRevenue;
|
|
||||||
private WriteSportsRevenue writeSportsRevenue;
|
|
||||||
|
|
||||||
public SportsApp(FetchSportsRevenue sportsCategories, WriteSportsRevenue writeSportsRevenue) {
|
|
||||||
this.sportsRevenue = sportsCategories;
|
|
||||||
this.writeSportsRevenue = writeSportsRevenue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fetchAndWrite(String sportName) {
|
|
||||||
SportRevenue sportRevenue = sportsRevenue.retrieveSportRevenue(sportName);
|
|
||||||
writeSportsRevenue.writeSportsReveue(sportRevenue);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.model;
|
|
||||||
|
|
||||||
public class SportRevenue {
|
|
||||||
private String name;
|
|
||||||
private double revenue;
|
|
||||||
|
|
||||||
public SportRevenue(String name, double revenue) {
|
|
||||||
this.name = name;
|
|
||||||
this.revenue = revenue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
public double getRevenue() {
|
|
||||||
return revenue;
|
|
||||||
}
|
|
||||||
public void setRevenue(double revenue) {
|
|
||||||
this.revenue = revenue;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SportRevenue [name=" + name + ", revenue=" + revenue + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.ports;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.model.SportRevenue;
|
|
||||||
|
|
||||||
public interface FetchSportsRevenue {
|
|
||||||
public SportRevenue retrieveSportRevenue(String sportName);
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.ports;
|
|
||||||
|
|
||||||
public interface UserRequest {
|
|
||||||
public void processRequest(String sportName);
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.baeldung.hexagonal.ports;
|
|
||||||
|
|
||||||
import com.baeldung.hexagonal.model.SportRevenue;
|
|
||||||
|
|
||||||
public interface WriteSportsRevenue {
|
|
||||||
public void writeSportsReveue(SportRevenue sportRevenue);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user