Questions tagged [factory-method]
The factory-method tag has no summary.
73 questions
4 votes
3 answers
3k views
What is a SOLID way for creating objects dynamically using a factory?
Description I want to create an instance of an object at runtime, however, the parameters used to create the object are not always the same. To help explain, I have created a simplified example (in ...
0 votes
0 answers
1k views
Abstract Factory for methods/constructor with different arguments
I have the following classes in my system (python): class Metric(ABC): def compute(self): -> float class Visualization(ABC) def visualize(self) class FirstMetric(Metric) def __init__(...
0 votes
3 answers
769 views
Is it a code smell to have a static factory method on the base class?
Suppose we have a BaseModel, which has a type enum, and derived models with same constructor signatures to each other, whose implementations are like : public DerivedModelJ(Object arg1, ..., Object ...
-2 votes
1 answer
684 views
How to implement factory pattern in following case?
I have a program which downloads web pages and then scrapes html to create domain specific collection objects e.g. ProductCollection, CatalogCollection, NewsCollection and more. The idea is to create ...
0 votes
2 answers
600 views
Overkill to apply abstract factory pattern for a single object creation?
I need to vary the object creation at (*). public class Parser { // Problem code public List<FileOption> methodA() { // Does something ... fileOptions....
3 votes
1 answer
2k views
Factory Method Pattern - the problem and what does it do to solve it
I always had problems in grasping the full benefits/motif behind using the Factory design pattern (for this post, I will stick to Factory Method pattern, specifically). True, there are (really) lots ...
21 votes
6 answers
13k views
Strategy vs Factory design pattern
I am new to design patterns and working my way through the Factory Method and Strategy patterns. I understand that Factory is a creational pattern and Strategy is behavioral but I struggle to ...
5 votes
5 answers
4k views
Factories and static methods
So almost every post I read about oop by purists, they keep stressing about how using static methods is anti pattern and breaks the testability of the code. On the other hand every time I look for ...