我正在嘗試編寫適配器。我有近50個屬性,我試圖從一個類適應另一個。在java中編寫適配器時的最佳做法
我的代碼如下所示:
public static Type2 getType2(Type1 type1)
{
...
if(!StringUtils.isEmpty(type1.getAttribute1()) {
type2.setAttribute1(type1.getAttribute1());
}
// and so on for all the 50 attributes
...
}
有沒有更好的方式來寫這個適配器方法?
適配器是否會反映'Type1'中的實時更改?這看起來更像是一個bean複製操作。 – McDowell
最佳做法是不要有50個屬性。另外,嘗試推土機的反光豆複印機。 – artbristol