网站开发

asp.net
随笔 - 30, 文章 - 0, 评论 - 9, 引用 - 0
数据加载中……

IList GetCategories();的问题

petshop4.0中的一段代码  
   
  public   interface   ICategory   {  
   
  ///   <summary>  
  ///   Method   to   get   all   categories  
  ///   </summary>  
                  ///   <returns>Interface   to   Model   Collection   Generic   of   categories</returns>  
             
                 
  IList<CategoryInfo>   GetCategories();  
                 
   
                  ///   <summary>  
                  ///   Get   information   on   a   specific   category  
                  ///   </summary>  
                  ///   <param   name="categoryId">Unique   identifier   for   a   category</param>  
                  ///   <returns>Business   Entity   representing   an   category</returns>  
                  CategoryInfo   GetCategory(string   categoryId);  
  }  
   
   
  我知道IList<CategoryInfo>是范型  
  表示list中的item是CategoryInfo对象  
   
   
  请问为什么用IList<CategoryInfo>  
  用List<CategoryInfo>可以吗?  
   
  两者有什么区别?谢谢  

没有什么区别,这样写灵活性大,实现ilist接口的类很多,你写成list后,也许以后你要改成非list的,就会要改很多代码
举个例子  
   
  RenderControlToString(DataList   L//Control   C)  
   
  你认为是写control还是写datalist代码的通用性高?

  OOP编码原则:尽可能用接口编程

posted on 2007-12-26 11:44 风雨兼程 阅读(450) 评论(0)  编辑  收藏 所属分类: Petshop4.0 案例分析


只有注册用户登录后才能发表评论。


网站导航: