java - Should be localization part of domain in DDD -


while following ddd concept i'm struggling on decision if should make domain localization aware? came 2 two solutions how solve this. both makes domain localization aware in different places. should place localized text domain? share solution problem or pros , cons of 2 examples. thanks.

example 1

class persion {    string name;    // other fields ommited    void rename(string newname) {     string oldname = this.name;     this.name = newname      // publish event old name , new name   }    string name() {     return name;   } }  class persionrepository {    void store(persion persion) {     locale loc = localecontextholder.get().getlocale();      // store object dao - create/update fields context locale   }    // other methods ommited } 

example 2

class persion {    map<locale, string> name;    // other fields ommited    void rename(string newname) {     locale locale = localecontextholder.get().getlocale();     string oldname = this.name.put(locale, newname);      // publish event old name , new name   }    string name() {     locale locale = localecontextholder.get().getlocale();     return this.name.get(locale);   } }  class persionrepository {    void store(persion persion) {     // store object dao - create/update fields locales   }    // other methods ommited } 

in of cases, best option remove localization domain.

domain classes should contain data relevant invariants, since responsible business rules. retrieve localized descriptions, use projective dtos , applicative services.

you use this:

public final class vatcode {     private final string _code;     public vatcode(string code)     {         // vat code validation here...         _code = code;     }      @override     public string tostring() {         return _code;     }      @override     public boolean equals(object obj) {         // ...     }      @override     public int hashcode() {         // ...     } }  public class person {     private final vatcode _identifier;      public person(vatcode identifier)     {         _identifier = identifier;     }      // command , query here... }  public class persondto {     private final string _vatcode;     private final string _personaldescription;      public persondto(string _vatcode, string _personaldescription) {         this._vatcode = _vatcode;         this._personaldescription = _personaldescription;     }     // other fields here...      public string getvatcode()     {         return _vatcode;     }      public string getpersonaldescription()     {         return _personaldescription;     }      // more getter here }  public interface localizedpersonalinformationservice {     persondto getinformationof(vatcode person, locale localization) throws properexceptionlist; } 

that is:

  • something vatcode valueobject (that overrides equals, hashcode , tostring) identify person entity
  • a person entity, holding minimum amount of data required ensure business invariants , exposing set of command , queries
  • a persondto carries useful descriptions (some call read-model)
  • a localizedpersonalinformationservice able provide persondtos.
  • and (obviously) needed exceptions... :-)

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -