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
193
views
factory methods in JPA entity classes. anti pattern?
I started using factory methods in JPA Entity classes. But I'm not sure if it's an anti-pattern. If it is , then where do I place them instead ?
A similar sample is below
@Builder
@Entity
Class ...
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__(...
2
votes
2
answers
765
views
The motivation behind the Factory Method design pattern
I'm learning about the Factory Method Desing Pattern and I'm having a hard time to understand exactly what it tries to solve and how.
Let's first introduce the example that Wikipedia uses to have a ...
0
votes
3
answers
792
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 ...
1
vote
2
answers
3k
views
Can a class be considered as a factory even though it only creates one concrete type of objects?
I have a simple class called Link that contains some properties, and use different classes for creating different types of links.
My code looks like this:
class Link {
String reference, label, ...
-2
votes
1
answer
705
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
157
views
Is my analogy of an Abstract Factory valid?
After working through several tutorials and reading various responses on this site, I believe the Abstract Factory pattern would work well for a current project. I am seeking the opinions of those ...
0
votes
2
answers
633
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....
1
vote
1
answer
303
views
Is this a good use of template specialization? Or should the factory method be used?
I have a program that involves two different data structures, and so I created a class that acts as a generalized data structure that either of the original two can be represented as. (Because the ...
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 ...
2
votes
1
answer
592
views
Should I use Factory Method design pattern for this problem?
I'm working on an application which needs to open a database file. There are 2 "versions" of this database: one of them is more general data storage, and the other contains "less" information. That ...
21
votes
6
answers
14k
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 ...
0
votes
2
answers
512
views
SimpleFactory vs Factory Method
Let's assume a SimpleFactory that creates a group of objects:
public SimpleFactory {
public Bycicle createBycicle(String type) {
if(type.equals("ONE")) return new OneWheelBycicle();
if(...
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 ...