DDD Service Example

This program models DDD service.

Problem Statement

Write a Java program where PaymentService performs domain logic not belonging to entity.

Source Code

1 class Order {
2 String product; double amount;
3 Order(String p,double a){ product=p; amount=a; }
4 }
5 class PaymentService {
6 void pay(Order o){ System.out.println("Payment done for "+o.product+", Amount: "+o.amount); }
7 }
8 public class DDDService {
9 public static void main(String[] args) {
10 System.out.println("Eduinq DDD Service");
11 Order o=new Order("Mobile",15000);
12 PaymentService ps=new PaymentService();
13 ps.pay(o);
14 }
15 }

Program Output

Eduinq DDD Service
Payment done for Mobile, Amount: 15000.0

Explanation

Services encapsulate domain logic not tied to entities or value objects. - PaymentService handles payment logic for Order. - This demonstrates DDD service concept, promoting separation of concerns. Conclusion: Shows DDD service example.

Quick Links to Explore