Let's say I have a class that just stores data:
ClassData
Field1
Field2
Field3
Now let's say I have a function that uses Field1 and Field2:
public void DoStuff(string field1, string field2){
if(field1 == "something"){
//Do something
}
if(field2 == "somethingElse"){
//Do something else
}
}
vs
public void DoStuff(ClassData data){
if(data.field1 == "something"){
//Do something
}
if(data.field2 == "somethingElse"){
//Do something else
}
}
It seems like this is a type of "more art than science" type thing, but I have a few thoughts also. Passing specific fields shows you the required information right from the get-go, which can make it easier to read and understand the function. Sending just the data object does have advantages because it makes the code look cleaner. I wouldn't be surprised if I'm missing pros and cons for both and would be interested in hearing what you think. Thanks!