享受代码,享受人生

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.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

每日代码 - 7/1 减小方法参数的依赖

Posted on 2013-07-01 11:03  idior  阅读(765)  评论(0编辑  收藏  举报
 public List<ItemDetail> queryItemDetails(List<Cart> carts){
    ItemRepository itemRepository=...; 
        List<ItemDetail> result = List.newArrayList();
        
 
        List<SkuId> ids = buildItemSkuIds(carts);
        result = itemReposioty.query(itemSkuIds);

//Do some additional things to the result...
return result; }

无意义地的扩大方法的依赖。在本例中, queryItemDetail中其实仅仅用到了carts的中的id属性,却需要调用者传入整个carts列表,无谓地使得该方法所依赖的参数扩大了。同样List<T>这个参数类型也没有太大意义,Iterable<T>很可能就足够了。