c# - SOLID-principle attempt, solid or not solid? -
in our layered architecture designing bll logic component called apphandover , have written basic high level code this. want follow solid-principles , loosly coupled, adopt separation of concern , testable.
here apphandover should do
- check if user owns app. if not throw error
- remove history if possible (ie no more apps assigned user)
- transfer ownership next instance
quesion is, on right track , following sample seem solid?
public interface itransferownership { void transferownership(string userid, string appid, transferdirection transferdirection); } public interface iownershipverification { bool userownsapp(string userid, int budgetid, string appid); } public interface ipreservehistorycheck { bool shoulddeletetemporarybudgetdata(string userid, int budgetid); } public interface iremovehistory { void deletetemporarybudgetdata(string userid, int budgetid); }
handover process implementation
public class apphandoverprocess : konstruktdbcontext, itransferownership { private iownershipverification _ownershipverification; private ipreservehistorycheck _preservehistory; private iremovehistory _removehistory; private itransferownership _transferownership; public apphandoverprocess() { } public apphandoverprocess(iownershipverification ownershipverification, ipreservehistorycheck preservehistory, iremovehistory removehistory) { _ownershipverification = ownershipverification; _preservehistory = preservehistory; _removehistory = removehistory; } public void performapphandover(string userid, string appid, int budgetid) { if (_ownershipverification.userownsapp(userid,budgetid,appid)) { if (_preservehistory.shoulddeletetemporarybudgetdata(userid, budgetid)) { _removehistory.deletetemporarybudgetdata(userid, budgetid); } //handover logic here.. _transferownership.transferownership(userid, appid, transferdirection.forward); } else { throw new exception("apphandover: user not own app, data cannot handed over"); } } }
concerning code outlined above think you're on right track. push design little further , define transferownership additional interface.
following approach apphandoverprocess decoupled it's client , behaviour defined in service configuration.
enforcing isolation transferownership allow unittest object implementing interface without need mock apphandoverprocess dependency.
also apphandoverprocess test should trivial thing you'll need make sure services invoke or exception thrown.
hope make sense,
regards.
Comments
Post a Comment