網站開發

          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 風雨兼程 閱讀(472) 評論(0)  編輯  收藏 所屬分類: Petshop4.0 案例分析

          主站蜘蛛池模板: 上高县| 禹城市| 昌宁县| 平遥县| 福泉市| 湘西| 准格尔旗| 万宁市| 宾阳县| 邵阳县| 孝感市| 盐边县| 栖霞市| 新野县| 乌拉特后旗| 平原县| 奇台县| 永善县| 顺昌县| 迭部县| 偃师市| 合作市| 广德县| 石屏县| 贵溪市| 鹿邑县| 清河县| 丹江口市| 邻水| 夏河县| 比如县| 基隆市| 平谷区| 临江市| 新邵县| 林口县| 阿鲁科尔沁旗| 安阳县| 乐昌市| 景德镇市| 绥宁县|