這是一個更好的方法,就代碼重用而言,代碼修改? 當我需要在將來爲savePayment
方法添加新參數時,我可能需要在許多控制器文件中更改paymentDao.savePayment()
方法。 我也想過創建另一個類只是爲了傳遞參數,就像paymentDao.savePayment(parameterClass)
這是一個更好的解決方案嗎?還是有比這更好的解決方案?更好的編寫代碼的方法
paymentDao.savePayment(fromUserId, toUserId, amount, paymentMethod, note, paymentGateway);
class PaymentDaoImpl implements PaymentDao{
public void savePayment(long fromUserId, long toUserId, double amount String paymentMethod, String note, String paymentGateway){
PaymentStdReln paymentStdReln = new PaymentStdReln();
paymentStdReln.setFromUser(fromUserId);
paymentStdReln.setToUserId(toUserId);
paymentStdRelnDao.save(paymentStdReln);
PaymentGateway pg = new PaymentGateway();
pg.setGateway(paymentGateway);
paymentGateWayDao.save(pg);
.....
//In this way save into many table
}
}
http://codereview.stackexchange.com/ – Quentin 2012-04-26 14:52:48