我有下面的代碼依次執行,方法依次執行。我應該使用哪種設計模式?
我加載的要求,進行了幾個檢查如檢查是否有響應已經存在這個要求,如果沒有,我所說的服務,並接受我保存到數據庫的響應。
我一直在尋找一種設計模式,我可以在這樣的情況下使用,我想在這裏張貼這一點,並得到一些想法。
public class Manager
{
public void PutRequest()
{
//Do Something
if (loadRequest())
{
callService();
//Do Something
saveResponse();
}
}
private bool loadRequest()
{
bool isExist = checkIfResponseExists();
if (!isExist)
{
// If false, load request from DB
}
return !isExist;
}
private bool checkIfDataExists()
{
//Check if a response already exists in the DB for this request
}
private void callService()
{
//Call the service and receive the response
}
private void saveResponse()
{
//Store the response in the DB
}
}
爲什麼你使用'方法2()'因爲它調用'方法3()'?那麼立即調用'method3()'怎麼樣? :) –
等等....不都是那些屬性? :P –
如果method3返回false,則Method2從DB加載請求。這些實際上是代碼的小型版本,還有更多的方法和更多的代碼。我只是試圖說明我的意思是說代碼按順序執行。 –