I have always been tought to avoid using static methods. But i've also been tought to try to keep my code as readable and short as possible.
I have a list of proxies and for all of them i should perform 5 different validation.
For me these validation are so different that i don't feel like putting them in 1 big validation class. Especially if the validation will be extended this class could grow to large.
Now in this case i can write my validator class this way:
Public Class MyValidator1
Public Shared Sub Validate(proxy As ServiceClient, year As Integer)
Dim args = New Arguments()
args.Year= year
Try
Console.WriteLine("Test")
Console.WriteLine("--------------")
Dim result = proxy.GeneratReport(args)
Console.WriteLine("No errors")
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
Console.WriteLine()
End Try
End Sub
End Class
this is how it is implemented:
For Each proxy In _proxies
Console.WriteLine(proxy.Endpoint.Address.Uri.Host)
Console.WriteLine("------------------------")
MyValidator1.Validate(proxy.Value, jaar)
MyValidator2.Validate(proxy.Value, jaar)
MyValidator3.Validate(proxy.Value, jaar)
MyValidator4.Validate(proxy.Value, jaar)
MyValidator5.Validate(proxy.Value, jaar)
Next
I can offcourse make my methods non-static/shared but this would require me to create an instance of every validator.
What would be the pro and cons of each choice. For me it is easyer to read with static implementations.