I m working on a system which get thousands of requests per second, and essentially one of the tasks we are trying to avoid is to create unnecessary/extra objects.
We need to validate incoming request for 6 request items per se.
I m thinking of creating a class per each item validation.
However, I m trying to justify if i should use static validation classes vs object with instances that contains HttpRequest as the instance field.
should i use static classes or objects? what would you do?
Essentially, what I m doing is injecting List<IValidator> validators to request handler and iterating over it. but not sure if i should have an instance vs static classes.
Have you actually measured the impact creating new Validator instances has on memory versus re-using static methods? The cost of using a short-lived object is very, very small. You should measure what the difference between the two approaches is and if there is no measurable difference, use the one where the code is cleaner and easier to understand.
In cases like this it always makes sense to measure the difference instead of just assuming one versus the other is better.