In what cases does it make sense to use factory classes instead of static functions?

Currently, I have created the ABCFactory class, which has the only method for creating ABC objects. Now that I think about it, perhaps instead of having a factory, I could just create a static method in my ABC method. What are the pro and necessity of making such a change? Would it lead to the same? I do not expect other classes to inherit ABC, but no one knows!

thank

+5
source share
6 answers

, factory, . factory , . , factory Unicorns, IFourHoovedAnimal. , IFourHoovedAnimal . factory, Pegasus, IFourHoovedAnimal. Pegasus, factory! PegasusFactory UnicornFactory ( ).

, , factory, factory , . , factory, .

( factory , ) , , , - , . , ASP.NET, . , , .

, factory, , . , " " .

+2

, - . , .

, , .

+4

factory . , factory , . factory - , singleton-pattern.

+3

factory - ( , , , , factory ).

factory , .

+1

"D" SOLID - - " " , .

, , factory . "" ( ) . () , factory.

, .

+1

Excessive use of design patterns is dangerous, and design design patterns make sense if you have class hierarchies with specific interfaces or you need to create fairly complex objects. If you have a simple design, use simple solutions. Therefore, in your case, the Factory Method will be enough

Yes, you're right, this is another design template :)

+1
source

All Articles