我在管理给定通用事务的持久性机制的边界类上有一些事件处理程序:
void MyBoundaryClass::MyEventHandler(...)
{
//retrieve stuff from the UI
//...
//declare and initialize trasaction to persist
SimpleTransaction myTransaction(.../*pass down stuff*/);
//do some other checks
//...
//declare transaction persistor
TransactionPersistor myPersistor(myTransaction, .../*pass down connection to DB and other stuff*/);
//persist transaction
try
{
myPersistor.Persist();
}
catch(...)
{
//handle errors
}
}
使用某种 TransactionManager 来包装 SimpleTransaction 和 TransactionPERsistor 对象会更好吗?
是否有任何有用的经验法则可以理解我是否需要进一步的封装?
目前我遵循的经验法则是“如果方法变得太大 - 做点什么”。在处理边界事件处理程序时,有时很难在过程和面向对象之间找到正确的平衡。
有什么意见吗?
干杯