zoukankan      html  css  js  c++  java
  • 两种实现模式,还是选择2,少一层继承。

     public class Model
        {
     
        }
     
     
        public interface IRepository<TEntity>
        {
            /// <summary>
            /// Gets entity by key.
            /// </summary>
            /// <typeparam name="TEntity">The type of the entity.</typeparam>
            /// <param name="keyValue">The key value.</param>
            /// <returns></returns>
            TEntity GetByKey(object keyValue);
        }
     
        public interface IRepository
        {
            /// <summary>
            /// Gets entity by key.
            /// </summary>
            /// <typeparam name="TEntity">The type of the entity.</typeparam>
            /// <param name="keyValue">The key value.</param>
            /// <returns></returns>
            TEntity GetByKey<TEntity>(object keyValue) where TEntity : class;
        }
     
     
        public class BaseRepository   : IRepository 
        {
     
            public TEntity GetByKey<TEntity>(object keyValue) where TEntity : class
            {
                throw new NotImplementedException();
            }
        }
     
        public class BaseRepository<T> : BaseRepository, IRepository<T> where T : class
        {
     
            public T GetByKey(object keyValue)
            {
                return this.GetByKey<T>(keyValue);
            }
        }
     
        public class BaseRepository2<T> : IRepository, IRepository<T> where T : class
        {
     
            public T GetByKey(object keyValue)
            {
                return this.GetByKey<T>(keyValue);
            }
     
            public TEntity GetByKey<TEntity>(object keyValue) where TEntity : class
            {
                throw new NotImplementedException();
            }
        }
     
     
     
     
     
        public interface IBiz
        {
            void Get();
        }
     
        class bbb : BaseRepository<Object>, IBiz
        {
     
            public void Get()
            {
                this.GetByKey(1);
                this.GetByKey<Model>(1);
            }
        }
     
  • 相关阅读:
    Android的Activity屏幕切换动画(一)-左右滑动切换
    404 Not Found 由来
    HTML+CSS 制作HTML5标志图
    发现 网站错误
    链接指南
    偷懒省事有工具啊
    程序员很穷(转)
    谷歌浏览器修改CSS和js后同步保存到文件中 (译)
    程序员眼睛的保护(爱护眼睛,你我做起)
    仿站违法和侵权吗?
  • 原文地址:https://www.cnblogs.com/zbw911/p/2882634.html
Copyright © 2011-2022 走看看