只是一个框架而已,关于ActiveRecord的开发,请参考terrylee的Castle开发相关文章。因为在进行开发框架封装的时候遇到了为了考虑简化而忽略了不同业务对象调用的问题,所以现在将UIBase补充了一个泛型参数,但是这样使得看起来要复杂得多。写出来想听听大家的意见!
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
#region 数据库访问层
/// <summary>
/// 数据库层基类。
/// </summary>
/// <typeparam name="T"></typeparam>
abstract class ModelBase<T>
{
public ModelBase()
{
}
public abstract string Current
{
get;
}
}
/// <summary>
/// 数据库及实体层。
/// </summary>
class model : ModelBase<model>
{
public model()
{
}
public override string Current
{
get { return "model"; }
}
}
#endregion
#region 业务层
/// <summary>
/// 业务层。
/// </summary>
/// <typeparam name="Model"></typeparam>
class Controller<Model> where Model : ModelBase<Model>, new()
{
public Controller()
{
}
Model _model;
public string GetCurrent()
{
_model = new Model();
return _model.Current;
}
}
#endregion
#region 界面层
/// <summary>
/// 界面层。通过泛型参数实现调用不同的业务对象和数据库对象。
/// </summary>
/// <typeparam name="M"></typeparam>
/// <typeparam name="C"></typeparam>
class UIBase<M,C> where C : Controller<M>,new() where M : ModelBase<M>,new()
{
C _c = new C();
public UIBase()
{
}
public string GetCurrent()
{
return _c.GetCurrent();
}
}
#endregion
/// <summary>
/// 测试。
/// </summary>
class Program
{
static void Main(string[] args)
{
UIBase<model, Controller<model>> _base = new UIBase<model, Controller<model>>();
Console.WriteLine(_base.GetCurrent());
}
}
}
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
#region 数据库访问层
/// <summary>
/// 数据库层基类。
/// </summary>
/// <typeparam name="T"></typeparam>
abstract class ModelBase<T>
{
public ModelBase()
{
}
public abstract string Current
{
get;
}
}
/// <summary>
/// 数据库及实体层。
/// </summary>
class model : ModelBase<model>
{
public model()
{
}
public override string Current
{
get { return "model"; }
}
}
#endregion
#region 业务层
/// <summary>
/// 业务层。
/// </summary>
/// <typeparam name="Model"></typeparam>
class Controller<Model> where Model : ModelBase<Model>, new()
{
public Controller()
{
}
Model _model;
public string GetCurrent()
{
_model = new Model();
return _model.Current;
}
}
#endregion
#region 界面层
/// <summary>
/// 界面层。通过泛型参数实现调用不同的业务对象和数据库对象。
/// </summary>
/// <typeparam name="M"></typeparam>
/// <typeparam name="C"></typeparam>
class UIBase<M,C> where C : Controller<M>,new() where M : ModelBase<M>,new()
{
C _c = new C();
public UIBase()
{
}
public string GetCurrent()
{
return _c.GetCurrent();
}
}
#endregion
/// <summary>
/// 测试。
/// </summary>
class Program
{
static void Main(string[] args)
{
UIBase<model, Controller<model>> _base = new UIBase<model, Controller<model>>();
Console.WriteLine(_base.GetCurrent());
}
}
}
http://www.cnblogs.com/jinyong/archive/2007/04/10/707879.html