Skip to main content

Questions tagged [factory-pattern]

Filter by
Sorted by
Tagged with
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
1 vote
1 answer
192 views

I-m looking to learn better use of OOP principles/patterns so I decided to start implementing at least the basics of a GB emulator (technical part is widely covered on diff sites). So I started with ...
Allende's user avatar
  • 125
-1 votes
1 answer
105 views

In one of the project I am working on, I am facing a problem in terms of creating an object with a dependency that sits at a deeper level in the class composition. Following diagram shows the class ...
subtlecode's user avatar
-3 votes
1 answer
2k views

So I am learning how to use the factory function in javascript/typescript. I created a to-do list project where I had to pass the instance as a parameter to the function. I wanted to ask is it a bad ...
Mubashir Waheed's user avatar
2 votes
2 answers
729 views

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 ...
YoavKlein's user avatar
  • 172
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
1 vote
1 answer
486 views

I currently working on a parser project in C# and have run into problem. I have an entity folder within my project and within it I have: Entity IEntity.cs (defines a contract for entity classes) ...
Vocaloidas's user avatar
3 votes
5 answers
3k views

Say I have a hypothetical factory method whose single responsibility is to create MyObjects. However, MyObject should only ever be constructed with an ordered list. Further, MyObjects without an ...
ptk's user avatar
  • 185
3 votes
1 answer
593 views

Suppose I have the following entities: class Employee { public string Id { get; set; } public ICollection<EmployeeBadge> Badges { get; set; } } class Badge { public string Id { get; ...
Sara E's user avatar
  • 133
-2 votes
1 answer
589 views

I'm currently brushing up and learning about a bunch of techniques to hopefully begin implementing in my own workflow; one of which is IoC (and DI in particular). I'm hoping someone could clear up my ...
Buretto's user avatar
  • 117
-2 votes
1 answer
684 views

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 ...
Navjot Singh's user avatar
1 vote
2 answers
2k views

I need to document my design, in particular, the design patterns used, and would like to use the standard terminology. From Refactoring Guru, "Factory Method defines a method, which should be ...
Blue7's user avatar
  • 137
2 votes
0 answers
509 views

I'm writing a PHP web application (or actually a Symfony module). One part of it is a nested structure of ValueObjects (meaning: they are immutable and have to be validated on the creating). Such an ...
automatix's user avatar
0 votes
2 answers
2k views

Let's say I'm building a simple console app which has three commands: Create category. Download recipe from API to category. Display all recipes in a category. Assuming the app will grow, I use the ...
Lucas's user avatar
  • 139
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
1 vote
3 answers
3k views

Let's say your application takes in a user request and you don't trust the front-end validation (because you never trust the front-end validation). In your controller or other handler, you want to ...
user avatar
2 votes
1 answer
154 views

I have a function which takes the incoming request, parses the data and performs an action and posts the results to a webhook. This is running as background as a Celery Task. This function is a common ...
Arunmozhi's user avatar
  • 139
0 votes
2 answers
149 views

Given the following class in a Legacy code base without any UT's. So any refactoring done should be done on the smallest possible scale, just in order to be able to write UT's. public class Person { ...
Complexity's user avatar
0 votes
1 answer
2k views

I have recently encountered multiple articles with title Everytime a mock returns a mock a fairy dies And I ran into exact same situation while using factory class in my code. I am writing a sample ...
bharathp's user avatar
  • 103
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
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
  • 473
0 votes
3 answers
2k views

Currently, my aggregates and value objects have protected constructors and some of them are being created by static factory methods inside the aggregate with descriptive names. It creates a nice DSL ...
Mohsen's user avatar
  • 209
1 vote
2 answers
166 views

In my current project, I find my self making factories, but for two very distinct reasons: Reason #1: To assist my IoC container if a particular class needs an parameter that is only known when the ...
TheCatWhisperer's user avatar
1 vote
1 answer
210 views

Thinking about the overall architecture of the application logic: Current status: The model contains all resources that are used at runtime. In a factory you register a builder which is used to ...
user2366975's user avatar
5 votes
1 answer
228 views

I am designing a UI framework in Java. Every UI component, represented by the class Component, in the framework is identified by a non null unchangeable String key. So I get the key in the constructor ...
Durgadass S's user avatar
1 vote
1 answer
336 views

I've been working on different genetic algorithm selection methods recently. At the moment I have a RawFitnessSelction class, a RouletteWheelSelection class and a TournamentSelection class. I've been ...
JNMN's user avatar
  • 75
0 votes
4 answers
2k views

With two existing implementations, UFOEnemyShip & RocketEnemyShip, To introduce every new implementation implementing EnemyShip interface, shown below, changes are needed in factory class ...
user1787812's user avatar
0 votes
1 answer
154 views

I am trying to understand the factory design pattern and how it can be implemented in Javascript. So far what I understood is factory design pattern helps to create an instance of more specific class ...
Pravin's user avatar
  • 111
2 votes
2 answers
1k views

First SE stack, I am working on a large chunk of old Java code and am finding tons of duplication and inconsistently configured/created objects because of different authors, skill levels, etc. I ...
finleyarcher's user avatar
-1 votes
2 answers
179 views

I've come across something that I find decently frustrating while adding new functionality to our large existing code base. Preface We have a variety of classes (ItemA, ItemB, ItemC...) that ...
plast1k's user avatar
  • 1,569