[Edit]
My original-question was \"Why to decide between static and non-static? Both do the same...\"
Unfortunately it was edited to a C#-specific question wh
Static Methods are can be very useful, I love extension methods, but they force coupling and if used improperly can make testing a nightmare!
A good example of when to use a static is when you want to do so validation
public static errors Validate(Document myDoc)
{
..some validation code
}
this is very testable and it doesn't mater that your tightly coupling the method to an object. A Bad place to use a static method is when it dose something other then just return something, an example would be in a Biz layer that validates an object and if it passes validation it save the data to the DB
public static errors ValidateAndSave(Document myDoc)
{
errors docErrors = Validate(myDoc);
if(docErrors.count==0)
{
docErrors = SaveToDB(myDoc);
}
return docErrors;
}
This is a real pain to test because every time you run it, and it passes validation your taking to the database, your Biz logic may not generate an error but but your DAL layer might, so instead of only testing the functionality of the Biz layer your also having to test the DAL layer as well, and your tightly coupling your object, your Biz layer and your Dal together making this very hard to test and maintain.