DDD Value Object Example

This program models DDD value object.

Problem Statement

Write a Java program where Address is a value object.

Source Code

1 class Address {
2 String city; String state;
3 Address(String c,String s){ city=c; state=s; }
4 }
5 public class DDDValueObject {
6 public static void main(String[] args) {
7 System.out.println("Eduinq DDD Value Object");
8 Address a=new Address("Patna","Bihar");
9 System.out.println("Address: "+a.city+", "+a.state);
10 }
11 }

Program Output

Eduinq DDD Value Object
Address: Patna, Bihar

Explanation

Value objects represent concepts without identity. - Address is defined by its attributes, not by unique ID. - Immutable and replaceable, value objects improve clarity in domain models. Conclusion: Shows DDD value object example.

Quick Links to Explore