我目前正在重新工作的代码如下所示(pre++11):
FOO.CPP
if (CONDITION)
{
SyncThing thing;
}
else
{
AysncThing thing;
}
complete(bool isSuccess)
{
// parses status and clears up
}其中SyncThing和AsyncThing如下:
SYNCTHING.CPP
SyncThing::SyncThing()
{
// some complex synchronous stuff that calls Foo::complete() when done.
}ASYNCTHING.CPP
AsyncThing::AsyncThing()
{
// some complex asynchronous stuff that calls Foo::complete() when done.
}为了不让构造函数执行复杂的操作,并避免构造函数调用Foo::complete()的代码路径不明显,我希望从SyncThing的构造函数中删除复杂的内容,并将其放入一个单独的函数中,这个函数从Foo.cpp的逻辑中调用,如下所示:
FOO.CPP
if (CONDITION)
{
SyncThing thing;
bool didTheThing = thing.doSomeComplexSyncStuff();
complete(didTheThing);
}
else
{
AysncThing thing;
}
complete(bool isSuccess)
{
// parses status and clears up
}我认为这使得代码路径更容易遵循。
我的问题如下:
非常感谢!
发布于 2015-12-14 13:43:50
在我看来,最好的做法是为SyncThing和AsyncThing做一些类似于SyncThing和AsyncThing的事情。这对双方来说都很清楚
https://stackoverflow.com/questions/34268494
复制相似问题