I have a C# project in which I use the Memento/Command pattern to implement Undo/Redo functionality. The application is a WPF application that uses StructureMap for IOC, has extensive unit tests and makes use of mocking via interfaces using RhinoMocks.
In my code I have an Operation
class which represents all undoable operations, and I also have an IRepositoryWriter
interface through which all writes to the database are routed.
I am wondering what is the best way to enforce the policy that only Operation
and its derived classes should be able to use IRepositoryWriter
.
The obvious way to achieve this would be to make IRepositoryWriter
a protected, nested interface of Operation
.
Advantages: only Operation
and derived classes have access to IRepositoryWriter
.
Disadvantages: no longer can be used with StructureMap or Unit Tested.
What are some other solutions to this? The policy doesn't need to be strictly enforced - just enough to give a hint to someone else working on the codebase would be enough.