开发者

Design question: Different types of transactions in a system

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 bot开发者_运维技巧h 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?


Do 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜