I'm not sure which of these two βpatternsβ is the best. I am currently using option A (in conjunction with a provider to implement persistence), but now I am mistaken in the direction of B, especially in light of unit tests that can use the dependency injection model.
Option A:
class ClassA { ClassA() { } Save(); static List<ClassA> GetClassAs(); }
Option B:
class ClassA { ClassA() { } Save(); } class ClassARepository { ClassARepository() { } List<ClassA> GetClassAs(); }
I think I'm asking, is it good practice for a class to expose static methods that return collections of instances of itself?
Edit
There seems to be a general consensus that option B is the best choice. It looks like I have a lot of refactoring ahead: S
source share