简体   繁体   中英

.NET Deployment of Interface/Classes for Command Pattern Question

In theory I would like to produce 2 projects:

1) Asp.net (Sever A)

2) DAL running (Server B)

I would like to utilise command objects to comunicate with the DAL.

ASP.net instantiates a command class eg CmdGetAllUsers which impliments IMyCommand interface and sends it to the DAL (using ASMX or WCF).

My question is:

Would the class definition of CmdGetAllUsers need to exist on the DAL server? Or would having the interface definition be enough?

My goal is to reduce the need to redeploy the DAL code, and have it as a fairly simple pass-through layer.

Many thanks for your time.

To answer your question, no, the interface definition is not enough. It needs to have the concrete implementation because that's where the code to implement the methods lives. No code for the implementation, no execution.

On a larger note, why not just implement the methods in the service layer directly? Instead of passing a command back to your data layer to execute, have the service layer implement the method as a "command". Your DAL will be more conventional, but that's a good thing I think. Instead of scattering your DB code throughout all of the various Command class implementations, you'll have it localized in the DAL. You'll also have a central location (the service) to do any business-related rule-enforcement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM