Skip to content

Instantly share code, notes, and snippets.

@MufidJamaluddin
Created March 15, 2020 10:47
Show Gist options
  • Save MufidJamaluddin/66e0529e726cc9d15897831e72e28890 to your computer and use it in GitHub Desktop.
Save MufidJamaluddin/66e0529e726cc9d15897831e72e28890 to your computer and use it in GitHub Desktop.
Mengenal ValueObject pada DDD
using System;
// Value Object : Money
public class Money {
public double Value {get;set;}
public string Currency {get;set;}
public string Text {
get {
return String.Format("{0} {1}", this.Currency, this.Value);
}
}
}
// Book Entity
public class Book {
public int BookId {get;set;}
public string Title {get;set;}
public string ISBN {get;set;}
public Money Price {get;set;}
}
// Do something run
public class Program
{
public static void Main()
{
var book = new Book {BookId=1, Title="Laskar Pelangi", ISBN="9788858658055", Price=new Money{Currency="IDR", Value=135000}};
// output = 'The Laskar Pelangi price is IDR 135000'
Console.WriteLine(String.Format("The {0} price is {1}", book.Title, book.Price.Text));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment