DDD Modeling a value object and entities and types of dictionaries

I wanted to bring my question to a wider audience, since we have been discussing it in our company for some time and cannot find the answer.

Suppose we have a Transaction object, which is an aggregated root. Inside the Transaction , we have Money , which is the object of value.

class Transaction {
    private Money money;
    // other stuff
}

and

class Money {
    private BigDecimal amount;
    private String currency;
}

Such a Transaction can be saved (we use hibernate) for db in a simple table transaction

+-----------------+
| transaction     |
+-----------------+
|id : bigint      |
|amount: decimal  |
|currency: varchar|
|other...         |
+-----------------+

And everything would be great, but ... the client requires us to have a currency table in the database (we call it dictionary tables), and each table (including a transaction) that has money should point to a currency table:

+-----------------+           +-----------------+
| transaction     |           |curency          |
+-----------------+           +-----------------+
|id : bigint      |     +---> | id: bigint      |
|amount: decimal  |     |     | code: varchar   |
|curr_id: bigint  | ----+     | name: varchar   |
|other...         |           +-----------------+
+-----------------+

, Money :

class Money {
    private BigDecimal amount;
    private Currency currency;
}

value:( ? , , , . , , , , ddd.

. , , , Country FederalState ( ). , (, Institution) , FederalState. , simpe :

class Institution {
    Address address;
    // ...
}

class Address {
    String street;
    String houseNo;
    // etc..
    String federalState;
    String country;
}

, , :

class Address {
    String street;
    String houseNo;
    // etc..
    FederalState federalState;
}

, Address value. , , od ddd?

+4
1

" od ddd"

, . , , , :

  • ( )
  • "" - , , Enum ( ).

, - . . Currency: , Exchange Rate, / " exc.rate . State ( ) , (/ - ." " , ).

+1

Source: https://habr.com/ru/post/1656806/


All Articles