在遵循 DDD 概念时,我正在努力决定是否应该让我的域本地化意识?我提供了两种解决方案来解决这个问题。两者都使域本地化在不同的地方有意识。我什至应该将本地化文本放置到域中吗?分享您对此问题的解决方案或我的两个示例的优缺点。谢谢。
示例 1
class Persion {
String name;
// other fields ommited
void rename(String newName) {
String oldName = this.name;
this.name = newName
// publish event with old name and new name
}
String name() {
return name;
}
}
class PersionRepository {
void store(Persion persion) {
Locale loc = LocaleContextHolder.get().getLocale();
// store object to DAO - create/update fields for context locale
}
// other methods ommited
}
示例 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 with old name and new name
}
String name() {
Locale locale = LocaleContextHolder.get().getLocale();
return this.name.get(locale);
}
}
class PersionRepository {
void store(Persion persion) {
// store object to DAO - create/update fields for all locales
}
// other methods ommited
}