Questions tagged [factory]
In object-oriented programming (OOP), a factory is an object for creating other objects.
109 questions
2 votes
3 answers
226 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) ...
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 ...
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 ...
2 votes
3 answers
532 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
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 ...
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
3 answers
244 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 ...
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 ...