Created
March 15, 2020 10:47
-
-
Save MufidJamaluddin/66e0529e726cc9d15897831e72e28890 to your computer and use it in GitHub Desktop.
Mengenal ValueObject pada DDD
This file contains hidden or 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
| 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