我已经研究了好几个星期了.我目前正在使用n层(3层)方法和工厂设计方法设计松散耦合的架构设计.我的目标是将每个客户端的业务逻辑(ClientA.DLL,ClientB.DLL)放在单独的命名空间中,以便项目扩展,这意味着我可以修改/删除/添加特定客户端的业务逻辑而不会影响其他客户端,因为它们是不依赖于彼此.然后,我使用客户端的唯一标识符(在数据库中维护的字符串值)通过Factory命名空间调用客户端的名称空间/类.所述Factory.DLL还隐藏的每个客户端的逻辑,而BusinessAbstract.DLL 用作每个客户端类将使用的布局或模板.
这是项目解决方案:
这是实际的代码:
BusinessAbstract.DLL
namespace BusinessAbstract { // the entity / data transfer object public class MemberDTO { public string MemberID { get; set; } public string MemberName { get; set; } } // the interface public interface IMaintainable { void Add(); void Edit(); void Delete(); } // the base abstract class, implements the Entity and the Interface public abstract class Member : MemberDTO, IMaintainable { // Implement IMaintanable but change it to abstract public abstract void Add(); public abstract void Edit(); public abstract void Delete(); // a method with Database access, get from DAL public virtual MemberDTO GetMemberDetails(params object[] args) { return DAL.MemberDAL.FetchMemberDetails(args); } public virtual string GetClientBLL() { return "base's method"; } } }
ClientA实现了AbstractBusinessRule
ClientA.DLL
namespace ClientA { public class _Member : BusinessAbstract.Member { public override void Add() { throw new NotImplementedException(); } public override void Edit() { throw new NotImplementedException(); } public override void Delete() { throw new NotImplementedException(); } public override string GetClientBLL() { return "ClientA Method"; } } }
工厂
Factory.DLL
public static class Invoker { public static T GetMemberInstance(string clientCode) where T : Member, IMaintainable { Type objType = Type.GetType(clientCode + "._Member," + clientCode); return (T)Activator.CreateInstance(objType); } }
Presentation Tier上的示例实现
网站
protected void Page_Load(object sender, EventArgs e) { // invoke Member class using String hardcode Member obj = Invoker.GetMemberInstance("ClientA"); Response.Write(obj.GetClientBLL()); //prints clientA method obj = Invoker.GetMemberInstance ("ClientB"); Response.Write(obj.GetClientBLL()); //prints clientB method }
而且你还会注意到我在每个客户端DLL和AbstractBusinessRule DLL中都有一个DAL文件夹,因为我还想缩放DAL层并使用层结构"UI-BLL-DAL".
欢迎任何有关此设计的意见/建议.我希望能得到关于如何改进这种结构的意见.提前致谢.