Hi,
For the last year or so I have followed the idea that if a method could be static, to make it static, as this can have a performance benefit, and I have therefore ended up with some static classes in my applications.
I have since learned the performance benefit is not often large enough to be worthwhile, and also the distinction that methods that can be made static, perhaps shouldn't be from a design point of view, if they are more specific to the object, rather than the type - related question
As an example I have recently made a FileRepository class, that implements the repository pattern for our own File class (for example import files). This class is not static, and a repository object must first be created before it can be accessed.
My issue with this, is all my old static calls, are now 2 lines (unless I can re-use the object in local scope). The repository object (as yet) has no state, as it uses database access via a thread static variable.
My question is, what are people's opinions on having a thread static Current property on the class, where the get accessor initialises the object on the first call? As I understand it, this would still avoid the pitfalls of static classes, such as not being able to implement generic functionality via interfaces, but still offer the ease of single line calls to the repository object?
Just trying to adjust my practices and mindset for the better.