享受代码,享受人生

SOA is an integration solution. SOA is message oriented first.
The Key character of SOA is loosely coupled. SOA is enriched
by creating composite apps.
posts - 213, comments - 2314, trackbacks - 162, articles - 45
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

每日代码 - 6/28 代码逻辑分组

Posted on 2013-06-28 10:32 idior 阅读(...) 评论(...) 编辑 收藏
int officialShopId = shopId;
group.setShopId(officialShopId);
XmpUser xmpSeller = buildXmpUser(seller.getSellerInfo());
group.setSeller(xmpSeller);
List<XmpItem> xmpItems = buildXmpItemList(sellerList,clientName, officialShopId);
group.setItems(xmpItems);

以上代码看上去比较杂乱无章,可以做一个简单分组。

int officialShopId = shopId;
XmpUser xmpSeller = buildXmpUser(seller.getSellerInfo());
List<XmpItem> xmpItems = buildXmpItemList(sellerList,clientName, officialShopId);
                    
group.setShopId(officialShopId);  
group.setSeller(xmpSeller);
group.setItems(xmpItems);

这样就清晰很多,一方面可读性变好了,另一方面会便于进一步的重构,比如抽取小方法。

关于对象设置,C#的语法明显比java简洁多了。

group = new Group() { ShopId = officialShopId, 
                      Seller = xmpSeller,
                      Items = xmpItems
                    };

java下面可能用fluent API是种选择。

group.setShopId(officialShopId)
     .setSeller(xmpSeller)
     .setItems(xmpItems);