问题描述
我已经研究了数周.我目前正在使用 n 层(3 层)方法和工厂设计方法设计一个松散耦合架构设计.我的目标是将每个客户的业务逻辑(ClientA.DLL、ClientB.DLL)放在单独的命名空间中,以便项目横向扩展,这意味着我可以修改/删除/添加特定客户的业务逻辑而不影响其他客户,因为它们是不相互依赖.然后我使用客户端的唯一标识符(在数据库中维护的字符串值)通过 Factory 命名空间调用客户端的命名空间/类.Factory.DLL 还隐藏每个客户端的逻辑,而 BusinessAbstract.DLL 用作每个客户端的布局或模板类将使用.
I've been researching this for weeks. I'm currently designing a loosely-coupled architecture design using n-tier (3-layered) method and factory design approach. My goal is to put each client's business logic (ClientA.DLL, ClientB.DLL) in separate namespaces so that the project scales out, meaning I can modify/remove/add a specific client's business logic without affecting the others, because they're not dependent on each other. Then I invoke the client's namespaces/class using the client's unique identifier (a string value that is maintained in the database) via the Factory namespace. The Factory.DLL also hides the per-client logic, while the BusinessAbstract.DLL serves as the Layout or the Template that the per-client's classes will be using.
这里是项目解决方案:
这是实际代码:
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 implementation of the 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<T>(string clientCode)
where T : Member, IMaintainable
{
Type objType = Type.GetType(clientCode + "._Member," + clientCode);
return (T)Activator.CreateInstance(objType);
}
}
展示层的示例实现
网站
protected void Page_Load(object sender, EventArgs e)
{
// invoke Member class using String hardcode
Member obj = Invoker.GetMemberInstance<Member>("ClientA");
Response.Write(obj.GetClientBLL()); //prints clientA method
obj = Invoker.GetMemberInstance<Member>("ClientB");
Response.Write(obj.GetClientBLL()); //prints clientB method
}
您还会注意到,我在每个客户端 DLL 和 AbstractBusinessRule DLL 中都有一个 DAL 文件夹,因为我还想缩放 DAL 层并使用层结构UI-BLL-DAL".
And you'll also notice that I have a DAL folder in each of the client DLLs as well as the AbstractBusinessRule DLL, because I also want to scale the DAL layer and use the layer structure "UI-BLL-DAL."
欢迎对此设计提出任何意见/建议.我希望就如何改进这种结构提供意见.提前致谢.
Any comments/suggestion about this design are welcome. I'm hoping for input on how I can improve this structure. Thanks in advance.
推荐答案
我看到的唯一的东西,我不知道在看你的帖子时错过了这一点,但我没有看到 DAL 接口定义或抽象层将其与您的 BL 分开,就像您的 BL 从您的演示文稿中抽象出来一样.
The only thing I see, and I mist just be missing this in looking at your post, but I don't see a DAL interface definition or abstraction layer that seperates it from your BL in the way your BL is abstracted from your presentation.
这很重要,因为它使您将来可以灵活地使用相同的数据创建新的业务层,而无需重写 DAL,或在单元测试中用平面 CSV 文件/模拟替换您的数据库/第三方维护肥皂网络服务响应,或其他任何可能是未来更好的数据存储机制.
This is important because it gives you the flexibility in the future to create a new business layer using the same data without having to rewrite the DAL, or replacing your database with flat CSV files/mocks in unit testing/a 3rd party maintained soap web service response, or whatever else might be a better data storage mechanism in the future.
这篇关于创建松耦合/可扩展的软件架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!