將ArrayLists與EO(實體對象)轉換爲DTO對象的ArrayLists或Ids的ArrayLists的最有效方法是什麼?請記住,每個EO可能包含也是EO的屬性,或EO的集合,這些集合應在內部轉換爲DTO,或省略(取決於轉換策略)。一般來說,有很多樣板代碼。將集合從一種類型轉換爲另一種類型的策略
希望它是那麼簡單:
collectionOfUsers.toArrayList<UserDTO>();
或..
collectionOfUsers.toArrayList<IEntity>();
// has only an id, therefore it will be converted
// into a collection of objects, having only an id.
當然
,這可能是不錯的還有:
collectionOfUsers.toArrayList<Long>()
// does the same thing, returns only a bunch of ids
當然,有人要也要保持映射策略,例如Factory或者某事物。
有什麼建議嗎?