Skip to main content

Questions tagged [factory]

In object-oriented programming (OOP), a factory is an object for creating other objects.

Filter by
Sorted by
Tagged with
2 votes
3 answers
228 views

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) ...
sayanel's user avatar
  • 509
0 votes
2 answers
178 views

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 ...
Bernardo Benini Fantin's user avatar
4 votes
3 answers
3k views

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 ...
zwoolli's user avatar
  • 151
3 votes
1 answer
216 views

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 ...
Codisattva's user avatar
5 votes
6 answers
3k views

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 ...
CuriousGuy's user avatar
0 votes
2 answers
456 views

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 ...
Bernardo Benini Fantin's user avatar
2 votes
3 answers
535 views

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 ...
J. Mini's user avatar
  • 1,015
2 votes
5 answers
577 views

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 ...
Mike Warren's user avatar
2 votes
2 answers
170 views

Consider the following python3 code: from abc import ABC, abstractmethod class Food(ABC): _food_factory_map = {} _recipes = {} @classmethod def getFood(cls, foodName): return ...
raghavj's user avatar
  • 29
0 votes
1 answer
67 views

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 ...
dafie's user avatar
  • 109
29 votes
3 answers
12k views

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 ...
Bondolin's user avatar
  • 403
0 votes
4 answers
4k views

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 ...
Martin Braun's user avatar
0 votes
3 answers
245 views

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 ...
vargonian's user avatar
  • 337
0 votes
1 answer
844 views

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 ...
Tetra's user avatar
  • 3
2 votes
3 answers
393 views

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 ...
JansthcirlU's user avatar
-1 votes
1 answer
74 views

Assume the following class structure: class Base; class A : public Base; class B : public Base; class WrapperBase; class AWrapper : public WrapperBase; class BWrapper : public WrapperBase; I ...
Patrick Wright's user avatar
0 votes
3 answers
245 views

Ok I have a bunch of components that all have the same logic but have different css classes. So I wanted to create a sort of factory function that takes the names of the classes as its argument and ...
kaan_atakan's user avatar
1 vote
2 answers
3k views

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, ...
Harold L. Brown's user avatar
0 votes
2 answers
203 views

I have the following (hypothetical) setup and am wondering if anyone has design suggestions, keywords, or nudges. I have a class Walk that implements a method doActivity. This method keeps track of ...
Randabut's user avatar
-2 votes
1 answer
201 views

I have a scenario where user has multiple filters in a web application and a displayed list of items. In the gui it has multiple FilterGUI that he/she can tune interacting in the browser (these are ...
c0l1n's user avatar
  • 9
0 votes
0 answers
364 views

I have a C# class called FileTransferManager. Previously it took some parameters such as a username and password to connect to a FTP server. However now I have an additional requirement to support ...
ekolis's user avatar
  • 577
0 votes
2 answers
602 views

I need to vary the object creation at (*). public class Parser { // Problem code public List<FileOption> methodA() { // Does something ... fileOptions....
Sebastian Nielsen's user avatar
1 vote
1 answer
2k views

Status quo I created an aggregate, let's call it Foo. It has two entities within itself, let's call them Foo & Bar. You can mutate things by calling the aggregate's public methods. E.g. $foo->...
nkamm's user avatar
  • 69
3 votes
1 answer
619 views

I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication ...
YSA's user avatar
  • 141
0 votes
1 answer
339 views

I have these classes and I want to instantiate each one of them easily. All the data to create them are in a json file and there will be a lot of different objects in the end. Each objects have a lot ...
rXp's user avatar
  • 117
-2 votes
2 answers
2k views

My language is C#. I have a set of seven classes that all ultimately derive from a single class. The image of the class diagram is posted below. I will frequently need to iterate through collections ...
Eric's user avatar
  • 105
0 votes
0 answers
249 views

Brief description of a problem - providing factories which are creating same object type in different ways and following rules of DDD (isolated domain model, independent domain objects inside of it). ...
Bohdan's user avatar
  • 1
0 votes
2 answers
499 views

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(...
Asier Naiz's user avatar
5 votes
5 answers
4k views

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 ...
lahory's user avatar
  • 315
4 votes
8 answers
4k views

I get the idea of the factory pattern, but I feel that it is really not necessary to use this pattern. For example, below is some code I saw (C#) that use factory method: public interface IAnimal { ...
secondimage's user avatar
0 votes
3 answers
148 views

I am working on a simulator which simulates patients, so specific processes can be validated on "virtual" patients, before testing on real patients. The simulator is essentially a mathematical model ...
Gertjan Brouwer's user avatar
-3 votes
1 answer
243 views

I made a code that seems to mix Singleton design pattern, and Fatory method. But my factory method is in an abstract class inherited by my Singleton ... what the hell have I created ? Does it have a ...
Motiss's user avatar
  • 1
-1 votes
1 answer
382 views

In the below example, assume FooA and FooB each have constructors that have a large amount of dependencies being injected into them. If I have a class that needs to determine which IFoo ...
gilliduck's user avatar
  • 237
2 votes
3 answers
877 views

I have an application where I'm using pure DI to construct my object graph. I would like to use a factory so I can create and destroy instances of a certain class at run time. The trouble is that ...
Rob L's user avatar
  • 106
2 votes
2 answers
2k views

With the factory pattern we abstract the creation of objects. But what if we need a specific configuration of an object that depends on the calling context? Example: So I have a Builder pattern for ...
Jim's user avatar
  • 359
0 votes
1 answer
661 views

I'm reading a book in Design Patterns, and below is some code example used by the author. The author tries to build a html builder as (code in C#): public class HtmlElement { public string Name, ...
slowjams's user avatar
  • 127
0 votes
5 answers
1k views

I am studing the importance of the design pattern and I am not able to understand if could be a bad behavior to create a global static factory class (maybe using singleton?) I put an example hoping ...
micrus_'s user avatar
  • 19
8 votes
6 answers
2k views

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
vargonian's user avatar
  • 337
0 votes
1 answer
635 views

I am developing a desktop application that will be run at each station at a call center. It listens for an incoming call, and whenever a call arrives, there are about 30 different classes that need ...
Rob L's user avatar
  • 106
4 votes
2 answers
6k views

I'm quite inexperienced in design patterns and while I was studying them I got confused about the application of the Factory pattern. Wouldn't DI decouple the classes more than factory would do it? Or ...
MilitanteDoPT's user avatar
0 votes
1 answer
724 views

I'm busy playing around with some training material to help teach some of the juniors the factory pattern. Whilst writing the example, I can't help but think this might be an anti-pattern. Lets say ...
Darkestlyrics's user avatar
16 votes
4 answers
26k views

Let's say (just for the sake of example) I have three classes that implement IShape. One is a Square with a constructor of Square(int length). Second is a Triangle with a constructor of Triangle(int ...
Craig's user avatar
  • 483
0 votes
1 answer
631 views

I have several handlers classes that implements same interface and factories to create handlers. Handlers: public class Handler1 : IHandler { private readonly IService1 _service1; private ...
Alex Gurskiy's user avatar
1 vote
3 answers
296 views

I am trying to refactor a huge chunk of our software, and it requires to set up a factory. However, I am not sure where lies its responsibility. (PS: The code below is shown simply as an illustration ...
Yassine Badache's user avatar
3 votes
2 answers
4k views

A few developers and I are attempting to refactor a class that has grown too large. Currently this class is around 3K lines long. The goal of the refactor is to make the logic more maintainable. The ...
kontained's user avatar
-1 votes
2 answers
255 views

I have a class that provides basic functionality of a modal window. For different situations I need to provide different modals(different number of buttons, titles, etc...). I have a kind of factory ...
7368616d696c's user avatar
-1 votes
1 answer
5k views

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
Learn AspNet's user avatar
0 votes
4 answers
6k views

Which one of the following way is recommended and why? Date d = Date.from(curr); Date d = new Date(curr); Can you also provide some examples behind the reasoning?
hatellla's user avatar
  • 191
1 vote
1 answer
103 views

So I have a requirement for something like this: The client shouldn't be aware of how the actual classes are implemented or constructed. The classes implement a common interface So I used Factory ...
Zoso's user avatar
  • 251
1 vote
2 answers
670 views

I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning ...
brndng's user avatar
  • 19