Questions tagged [factory]
In object-oriented programming (OOP), a factory is an object for creating other objects.
109 questions
2
votes
3
answers
228
views
Adding "caller specific" special cases to a factory
So I have this setup with a factory:
class Base;
class A : public Base;
class B : public Base;
...
class Factory
{
public:
Base* CreateBase(std::string TypeToCreate, const Parameters& P)
...
0
votes
2
answers
177
views
How could I map a complex DTO to a Domain Aggregate in a Repository?
I'm working on a TypeScript application designed with DDD and using layered architecture. My infra layer has a repository that fetches a complex, nested DTO. My current implementation maps this DTO ...
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 ...
3
votes
1
answer
216
views
Seeking Clarification on the Abstract Factory Pattern
I am seeking clarification on the exact purpose and definition of the Abstract Factory pattern.
According to the GoF (Gang of Four) book, the intent of the pattern is to:
Provide an interface for ...
5
votes
6
answers
3k
views
Is it a good idea to return a Builder from a Factory?
I would want to have a builder for creating a complex object, for example Employee.
I would want to be able to create my objects in two ways:
Case 1. Get Employee with default values
Case 2. Get ...
0
votes
2
answers
456
views
Where to put factories that depend on the application layer?
I am a frontend developer (currently working with Vue and TS), and I have been searching for better organization of the frontend code and recently I got to know DDD a bit. I know DDD is mostly used ...
2
votes
3
answers
535
views
Is having many build-once factories a sign of bad dependency injection design?
I have a form. It contains things like grids. Users do things with these grids and what they do with them is sent to a SQL server. Clearly, the server is a volatile dependency and should be dependency ...
2
votes
5
answers
577
views
Is it a code smell for a factory to have many methods?
I have a testing project, in Katalon Studio, that uses data classes, called models. This is a conscious design decision.
Also a conscious design decision, is the decision to separate the concern of ...
2
votes
2
answers
170
views
OOP Best practices: Is there any reason to separate out Factory functionality from an abstract base class?
Consider the following python3 code:
from abc import ABC, abstractmethod
class Food(ABC):
_food_factory_map = {}
_recipes = {}
@classmethod
def getFood(cls, foodName):
return ...
0
votes
1
answer
67
views
Use factory design pattern to create a specific object
I am using this DTO class to pass object between web application layers
public class CreateProgressDTO
{
public int Total { get; set; }
public int Created { get; set; }
public decimal ...
29
votes
3
answers
12k
views
Is it Good Practice to Only Expose Interfaces
I''m working on a C# library where the API provides several public interfaces and a single concrete factory class (itself an interface implementation). This factory provides implementations of the ...
0
votes
4
answers
4k
views
Should I design a factory that returns a singleton?
I design a common API for selected printers of different brands in Java. Each printer uses a different underlying SDK with different functions, but any hardware my code runs on will have only one ...
0
votes
3
answers
245
views
If I have a ThingFactory which creates multiple concrete IThings, each with exclusive parameters, how do I avoid ThingFactory knowing about them all?
A common problem I run into is when I have a Factory (let's say ThingFactory) which creates multiple different IThing implementations, and each of these concrete implementation classes requires an ...
0
votes
1
answer
844
views
Unit testing parts that use a Value Object that is being created by a Factory
Here is the conundrum,
I have a fairly complex Value Object and I don't want to expose it's internals. It should not be an Entity since there is no need for attaching an identity to it. According to ...
2
votes
3
answers
393
views
Use abstract factory (or an alternative way) to produce an instance of a subclass?
Context for this question
I'm currently working with small data storage media (e.g. RFID tags) that contain some fixed number of bytes that can be manipulated. The drivers that allow reading bytes ...