-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchitectureExample.java
More file actions
53 lines (42 loc) · 1.18 KB
/
ArchitectureExample.java
File metadata and controls
53 lines (42 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Day 35 - Spring Boot: Architecture Example
*/
// Simulating Spring Boot layers
class Product {
public int id;
public String name;
public double price;
public Product(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
}
// Repository layer
class ProductRepository {
public Product findById(int id) {
return new Product(id, "Sample Product", 99.99);
}
}
// Service layer
class ProductService {
private ProductRepository repository = new ProductRepository();
public Product getProduct(int id) {
return repository.findById(id);
}
}
// Controller layer
class ProductController {
private ProductService service = new ProductService();
public void handleRequest(int id) {
Product product = service.getProduct(id);
System.out.println("Product: " + product.name + " - $" + product.price);
}
}
public class ArchitectureExample {
public static void main(String[] args) {
System.out.println("=== Spring Boot Architecture ===\n");
ProductController controller = new ProductController();
controller.handleRequest(1);
}
}