gpt4 book ai didi

java - 遵循哪种设计模式使代码结构化

转载 作者:行者123 更新时间:2023-11-29 09:05:56 25 4
gpt4 key购买 nike

我创建了一个名为“DownloadManagerWrapper 的类,它将根据运行时参数调用。我可以遵循以下代码的任何设计模式以使其干净和结构化吗?如果可能的话我可以选择哪种设计模式? 如果可能的话,需要您的建议和示例设计模式代码以及简单的解释,因为我是设计模式的新手。

public class DownloadManagerWrapper {

public static void main(String[] args) {
String downloadId = args[0];
String bankId =args[1];
String serviceId =args[2];
readInterfaceConfig(serviceId,bankId,downloadId);
}

public static void readInterfaceConfig(String intfCode,String bankId,String downloadId) {

Connection conn = CRMConnection.getConnection();

String statusOfDownload;
DownloadManager dwlManager = new DownloadManager();

ResultSet rs=null;

if(downloadId.equals("A"))
{
if(intfCode.equals("-1")) //all download
{
String query = "select INTF_CODE from CRMUSER.TABLE1 where bank_id ="+"'"+bankId+"'"+"order by INTF_CODE";
System.out.println("query>"+query);
try
{
Statement st = conn.createStatement();
rs = st.executeQuery(query);
while(rs.next())
{
String intfCodeFromDB = rs.getString("INTF_CODE");
statusOfDownload = new DownloadManager().downloadDataFromCore(intfCodeFromDB,bankId,downloadId);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
else //specific download
{
statusOfDownload = dwlManager.downloadDataFromCore(intfCode,bankId,downloadId);
}
}
else if(downloadId.equals("I"))
{
if(intfCode.equals("-1")) //all download
{
String query = "select INTF_CODE from CRMUSER.TABLE1 where bank_id ="+"'"+bankId+"'"+"order by INTF_CODE";
System.out.println("query>"+query);
try
{
Statement st = conn.createStatement();
rs = st.executeQuery(query);
while(rs.next())
{
String intfCodeFromDB = rs.getString("INTF_CODE");
statusOfDownload = new DownloadManager().downloadDataFromCore(intfCodeFromDB,bankId,downloadId);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
else //specific download
{
statusOfDownload = dwlManager.downloadDataFromCore(intfCode,bankId,downloadId);
}
}
}
}

最佳答案

一些提示:

关于java - 遵循哪种设计模式使代码结构化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15067281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com