Customer cust = new Customer();
cust.RecId = lblRecId.Text;
cust.CustCd = txtCustCd.Text;
cust.CustName = txtCustName.Text;
cust.Save();
OR
cust.SaveRecord(lblRecId.Text , txtCustCd.Text, txtCustName.Text)
both doing the same job, but which 1 is actually better? I and lead actually have an argue on this, I using the top method, as I can freely assign the value in any order, but he insist that the bottom 1 is better? no idea what actually to search, any 1 mind to give me some guideline on this
First one is much better approach. but it's a personal view.
Save should persist the current state of object. and state can be updated in other parts of program.
However having an overload Save is also not bad idea. but as the no. of fields increase the latter version becomes bulky and un-maintainable.
The first approach is great if you already have all the data for a customer in a customer class. If you do not have a customer class with data the second approach is better.
We often use the first approach, but then we also have some static methods to retrieve the customer with a specific key e.g.:
// A static method in Customer class.
public static Customer Get(string key)
{
Customer customer;
FCustomers.TryGetValue(key, out customer);
return customer;
}
This comes with a static constructor that loads all customers into memory and methods to Create, Save and Delete customers from database as well.
This is ofcause only relevant for data that is needed all the time, I don't think that customer is that kind of data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With