两种实现模式,还是选择2,少一层继承。
2013-01-30 11:11
323 查看
public class Model
[code]{
}
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);
}
}
[/code]
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
相关文章推荐
- 浅谈Observer模式的实现.基于继承和基于事件/委托的两种方式
- 使用了继承、多态还有工厂模式和反射,但是还是没有OO的感觉。[已经增加了实现的代码]
- 实现Thread类的两种方法(继承和实现runnable接口)
- C语言模式实现C++继承和多态
- Java中实现多线程有两种方法的区别:继承Thread类、实现Runnable接口
- shell实现菜单选择的两种方法
- c#单例模式 两种实现方式
- C语言模式实现C++继承和多态
- C++无法被继承的类实现以及单例模式的类的实现
- 组合还是继承,这是一个问题?——由模式谈面向对象的原则之多用组合、少用继承
- Qt多线程两种方式优劣,继承QThread还是MoveToThread
- 原型链实现继承的几种模式
- java子类继承父类实例-披萨的选择实现代码
- 单例模式的两种实现方式
- JAVA 线程的两种基本实现方法(继承Thread类和实现Runnable接口)
- 桥接模式(把接口和实现分为两个继承树,而不是将实现来继承接口,造成实现和接口耦合
- C++接口继承与实现继承的区别和选择
- 文件夹选择对话框 JS实现的两种方案
- PHP 单例模式继承的实现方式
- 【java】单例模式的两种实现方式