Created
March 14, 2023 11:18
-
-
Save Phury/27d0c041c5975f656006740c2ea5572f to your computer and use it in GitHub Desktop.
super power ninja turbo architecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// couche de présentation | |
public class TaskController { | |
private TaskService taskService; | |
public void addTask(String title, String description) { | |
Task task = new Task(title, description); | |
taskService.addTask(task); | |
} | |
public List<Task> getTasks() { | |
return taskService.getTasks(); | |
} | |
// ... | |
} | |
// couche de contrôle | |
public class TaskService { | |
private TaskRepository taskRepository; | |
public void addTask(Task task) { | |
taskRepository.save(task); | |
} | |
public List<Task> getTasks() { | |
return taskRepository.findAll(); | |
} | |
// ... | |
} | |
// couche de service | |
public interface TaskRepository { | |
void save(Task task); | |
List<Task> findAll(); | |
} | |
// couche de persistance | |
public class InMemoryTaskRepository implements TaskRepository { | |
private List<Task> tasks = new ArrayList<>(); | |
@Override | |
public void save(Task task) { | |
tasks.add(task); | |
} | |
@Override | |
public List<Task> findAll() { | |
return Collections.unmodifiableList(tasks); | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order implements AggregateRoot { | |
private OrderId orderId; | |
private CustomerId customerId; | |
private List<OrderLine> orderLines; | |
public Order(CustomerId customerId) { | |
this.orderId = new OrderId(); | |
this.customerId = customerId; | |
this.orderLines = new ArrayList<>(); | |
} | |
public void addOrderLine(ProductId productId, int quantity) { | |
OrderLine orderLine = new OrderLine(productId, quantity); | |
orderLines.add(orderLine); | |
} | |
// ... | |
} | |
public class Product implements Entity<ProductId> { | |
private ProductId id; | |
private String name; | |
private String description; | |
private Money price; | |
public Product(ProductId id, String name, String description, Money price) { | |
this.id = id; | |
this.name = name; | |
this.description = description; | |
this.price = price; | |
} | |
// ... | |
} | |
public class OrderService { | |
private OrderRepository orderRepository; | |
private ProductService productService; | |
public Order createOrder(CustomerId customerId, List<OrderLineRequest> orderLineRequests) { | |
Order order = new Order(customerId); | |
for (OrderLineRequest orderLineRequest : orderLineRequests) { | |
Product product = productService.getProductById(orderLineRequest.getProductId()); | |
order.addOrderLine(product.getId(), orderLineRequest.getQuantity()); | |
} | |
orderRepository.save(order); | |
return order; | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// port d'entrée | |
public interface BookController { | |
void addBook(String title, String author); | |
List<Book> getBooks(); | |
// ... | |
} | |
// port de sortie | |
public interface BookRepository { | |
void save(Book book); | |
List<Book> findAll(); | |
// ... | |
} | |
// adaptateur d'entrée | |
public class RestBookController implements BookController { | |
private BookService bookService; | |
public void addBook(String title, String author) { | |
Book book = new Book(title, author); | |
bookService.addBook(book); | |
} | |
public List<Book> getBooks() { | |
return bookService.getBooks(); | |
} | |
// ... | |
} | |
// adaptateur de sortie | |
public class InMemoryBookRepository implements BookRepository { | |
private List<Book> books = new ArrayList<>(); | |
public void save(Book book) { | |
books.add(book); | |
} | |
public List<Book> findAll() { | |
return Collections.unmodifiableList(books); | |
} | |
// ... | |
} | |
// cœur de l'application | |
public class BookService { | |
private BookRepository bookRepository; | |
public void addBook(Book book) { | |
bookRepository.save(book); | |
} | |
public List<Book> getBooks() { | |
return bookRepository.findAll(); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment