Am I violating the Single Responsibility Principle (SRP) if I put ‘data access’ methods on the business object? My gut feeling is the API feels more user friendly if the Load method is present on the class itself rather than having to guess which class the method happens to be in?
Example:
public class Image { public static Image FromFile(string filename) { return ImageLoader.LoadImage(filename) } public void SetPixel(int x, int y, Color color) { } }
i don’t see a problem with this per se other than there is no compelling reason for the static method to live in the Image class (since it doesn’t depend on anything in the class, but on the class itself).
if you end up with a bunch of load-from methods, they might be better in a different class