我的代码片段如下:
public void execute(Parameters params) {
Long requestType = params.getRequestType();
// Based on the requestType the name of the project would be different
getName(requestType);
// Same as above
getDescription(requestType)
// Project here is a collection of different requests
Long projectId = createProject(name, description)
RequestContents requestContents = params.getRequestContents();
for(RequestContent requestcontent : requestcontents) {
Long requestId = createRequest(name, description, projectId);
updateRequest(requestId, requestContent1);
}
// Based on the requestType, mail content would differ
String mailContent = getMailContent(requestType, projectId)
sendMail(mailContent);
}
函数sendMail
, createProject
,的输出createRequest
取决于requestType
,因此这些函数最终会具有多个if-else
条件。为此类建模以避免这种情况的正确方法是什么?