I don’t see anything bad in your constructor interface and I don’t see what the static method will deliver to you. I will have the same parameters, right?
Parameters do not seem optional, so there is no way to provide overload with less or use optional parameters.
From the perspective of the caller, it looks something like this:
Movie m = new Movie("Inception", 2010, Genre.Drama, 150, actors);
The goal of the factory is to provide you with a custom concrete instance of the interface, and not just call the constructor for you. The idea is that the exact class is not hardcoded at the construction site. Is it really better?
Movie m = Movie.Create("Inception", 2010, Genre.Drama, 150, actors);
It seems to me almost the same. The only thing that is better if Create() returns other concrete classes than Movie .
One thing to think about is to improve this so that the calling code is easy to understand. The most obvious problem for me is that it's not obvious what 150 means without looking at the code for Movie . There are several ways to improve this if you want:
With a smooth interface, your call will look like
Movie m = new Movie("Inception"). MadeIn(2010). InGenre(Genre.Drama). WithRuntimeLength(150). WithActors(actors);
Honestly, all this seems unnecessary for your business. Named parameters are reasonable if you are using .NET 4.0 because they are not much larger than the code and will improve the code of the caller.
Lou franco
source share