In my framewrok I have an ITransaction interface.
It implements some basic operations like Commit() and Rollback(), it is being used for flat files and other data sources.
However NHibernate has an ITransaction interface as well.
It is not the same as my interface since there are some database specific methods but there are similarities.
My problem is that I want a NHibernate transaction to be considered like my own transaction so I'll be able to switch implementations between database and flat files more easily.
How do I combine both interfaces so NHibernate will still be able to accept my NHibernate transaction objects and my framework will be able to accept my NHibernate transaction objects because they belong to MyFramework.ITransaction?
views:
30answers:
1Do you have a common base class, which could implement both NHibernate.ITransaction, and MyFramework.ITransaction? I don't know that I would create a common base class for the sole reason of implementing both these interfaces, but if you already have a common base class for other reasons, why not?
MyFramework.ITransaction could inherit from NHIbernate.ITransaction, ensuring that all implementors of MyFramework.ITransaction would also be implementors if NHibernate.ITransaction.
Finally, you could implement an Adapter pattern, with an ITransactionWraper, and 2 implementors (MyFrameworkTransactionWrapper and NHibernateTransactionWrapper). All your code would be written to the ITransactionWrapper interface, and its implementors would delegate calls to the correct ITransaction. Like most Adapter pattern implementations, you would likely use a Factory or AbstractFactory pattern to create the correct wrapper at run-time, as dictated by configuration.