So, we have the same animal factory example that we saw before:
The
RandomAnimalFactoryis a factory method that always creates a random animal. It does not have state, every time we invoke it, a randomAnimalis returned and theBalancedAnimalFactoryhas state, it starts to create a newAnimalbut then, only randomizes the other animals different that the ones that were already created.
Take a look at the code and analyze how the responsibility of creating a new Animal is statically created in the Program.cs file.
You can run the console application to see the output in the console.
To do that, you can use your IDE buttons/options or via terminal, executing the following command:
before executing the command,
cdto this repository root directory
dotnet run --project ./FactoryMethodPattern/FactoryMethodPattern.WithoutPattern/FactoryMethodPattern.WithoutPattern.csprojNow lets see the code using the factory method pattern 👇