views:

27

answers:

2

scenario:

you need to update 2 fields of a customer

you don't have a method UpdateCustomer yet anywhere in your project

Should you create a method called UpdateCustomer(Customer customer) that can take in a full customer object and just do an all update to all fields

or

for example (obviously the name is just for posting here) create an UpdateCustomer2Fields(string month, string year) and just update those 2 fields

I could imagine a shitload of UpdateCustomerThis UpdateCustomerThat

but if I just expose one UpdateCustomer, I can pass it a customer object and have it update anything and use this anywhere.

Good, Bad? which way to go.

A: 

Create a method called UpdateCustomer(Customer customer) that can take in a full customer object and just do an all update to all fields.

Keep it simple. Now you can spend your time on bigger problems.

FiveTools
I did keep it simple.
FiveTools
+1  A: 

You should just update all fields, unless there is a reason not to, to reduce your maintenance headaches.

Reasons not to update all fields. These are all very specific to environment, and are only valid if you've observed them in your situation.

  1. The vast majority of your transactions are updates, resulting in a heavy burden due to unnecessary data being passed over the network.
  2. A business or legal compliance requires you to log exactly what users changed which exact data with every transaction (these do exist). However, depending on the environment it may be best to log this at the database server.
  3. Some users should not have update access to some fields. This is architecture specific and relates to how you expose your functions. If someone must have certain credentials to update specific information, then generally, you will not want to have every transaction update everything. This can be dynamic, and may result in passing in a dictionary of fields to update (or a myriad of other choices). I typically run into this with tiered architectures using services with multiple consumers that have different access rights.
  4. Did I miss any?

Generally, the answer is just pass the entire object.

Russell Steen