Does it make sense to use interfaces for your domain object factories by default, or should interfaces be reserved for the factory classes only when you need them?
public IUserFactory { User CreateNewUser(); } public UserFactory : IUserFactory { public User CreateNewUser() { return new User(); } }
Here’s a translation of the same problem into Java.
Original example
Then the implementation of the Factory
I don’t see any special benefit to defining an interface for the factory, since you’re defining a single interface for a centralized producer. Typically I find that I need to produce many different implementations of the same kind of product, and my factory needs to consume many different kinds of parameters. That is, we might have:
The factory would look like this:
Hope this gets the point across.