I have a simple example of two setups of the same block of code, but i am not sure what would be considered the "better" option, although subjective, i read about methods often doing too much than which they describe.
So example is where i want to add data and do a sanity check first... the two choices would be:
public void Add(Data data)
{
if(sanitycheck(data))
{
// ADD to list
}
}
The second option - this seperates the logic into 2 methods:
public void Process(Data data)
{
if(sanitycheck(data))
{
Add(data);
}
}
private void Add(Data data) //private method
{
// ADD to list
}
I feel like the first one does "more than it says", but the second one could be unnecessary and cutting the methods a little too thin for their purpose.
This example is crude compared to real life situations but i am curious which is generally a more smarter approach and best practice as code complexity ramps up?
Data
object if it cannot be constructed with valid data. This has the consequence that you don't have to check again if your object is valid in other contexts because you know it already is. – Vincent Savard May 27 '17 at 19:51