What to name 2 methods with same signatures
- by coffeeaddict
Initially I had a method in our DL that would take in the object it's updating like so:
internal void UpdateCash(Cash Cash)
{
using (OurCustomDbConnection conn = CreateConnection("UpdateCash"))
{
conn.CommandText = @"update Cash
set captureID = @captureID,
ac_code = @acCode,
captureDate = @captureDate,
errmsg = @errorMessage,
isDebit = @isDebit,
SourceInfoID = @sourceInfoID,
PayPalTransactionInfoID = @payPalTransactionInfoID,
CreditCardTransactionInfoID = @CreditCardTransactionInfoID
where id = @cashID";
conn.AddParam("@captureID", cash.CaptureID);
conn.AddParam("@acCode", cash.ActionCode);
conn.AddParam("@captureDate", cash.CaptureDate);
conn.AddParam("@errorMessage", cash.ErrorMessage);
conn.AddParam("@isDebit", cyberCash.IsDebit);
conn.AddParam("@PayPalTransactionInfoID", cash.PayPalTransactionInfoID);
conn.AddParam("@CreditCardTransactionInfoID", cash.CreditCardTransactionInfoID);
conn.AddParam("@sourceInfoID", cash.SourceInfoID);
conn.AddParam("@cashID", cash.Id);
conn.ExecuteNonQuery();
}
}
My boss felt that creating an object every time just to update one or two fields is overkill. But I had a couple places in code using this. He recommended using just UpdateCash and sending in the ID for CAsh and field I want to update. Well the problem is I have 2 places in code using my original method. And those 2 places are updating 2 completely different fields in the Cash table. Before I was just able to get the existing Cash record and shove it into a Cash object, then update the properties I wanted to be updated in the DB, then send back the cash object to my method above.
I need some advice on what to do here. I have 2 methods and they have the same signature. I'm not quite sure what to rename these because both are updating 2 completely different fields in the Cash table:
internal void UpdateCash(int cashID, int paypalCaptureID)
{
using (OurCustomDbConnection conn = CreateConnection("UpdateCash"))
{
conn.CommandText = @"update Cash
set CaptureID = @paypalCaptureID
where id = @cashID";
conn.AddParam("@captureID", paypalCaptureID);
conn.ExecuteNonQuery();
}
}
internal void UpdateCash(int cashID, int PayPalTransactionInfoID)
{
using (OurCustomDbConnection conn = CreateConnection("UpdateCash"))
{
conn.CommandText = @"update Cash
set PaymentSourceID = @PayPalTransactionInfoID
where id = @cashID";
conn.AddParam("@PayPalTransactionInfoID", PayPalTransactionInfoID);
conn.ExecuteNonQuery();
}
}
So I thought hmm, maybe change the names to these so that they are now unique and somewhat explain what field its updating:
UpdateCashOrderID
UpdateCashTransactionInfoID
ok but that's not really very good names. And I can't go too generic, for example:
UpdateCashTransaction(int cashID, paypalTransactionID)
What if we have different types of transactionIDs that the cash record holds besides just the paypalTransactionInfoID? such as the creditCardInfoID? Then what? Transaction doesn't tell me what kind. And furthermore what if you're updating 2 fields so you have 2 params next to the cashID param:
UpdateCashTransaction(int cashID, paypalTransactionID, someOtherFieldIWantToUpdate)
see my frustration? what's the best way to handle this is my boss doesn't like my first route?