網站開發

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

          主站蜘蛛池模板: 甘南县| 延寿县| 大新县| 资溪县| 灵宝市| 德钦县| 砀山县| 舒城县| 平江县| 腾冲县| 白水县| 肃南| 慈溪市| 望城县| 永兴县| 丰顺县| 恩施市| 宜章县| 扬中市| 永吉县| 康乐县| 中江县| 宜都市| 唐海县| 华阴市| 石城县| 北辰区| 古浪县| 孝昌县| 阿拉善左旗| 台东市| 松滋市| 哈密市| 娄烦县| 长寿区| 大名县| 山西省| 漯河市| 庆云县| 邓州市| 开化县|