Questions tagged [factory-pattern]
The factory-pattern tag has no summary.
30 questions
4
votes
3
answers
2k
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 ...
1
vote
1
answer
164
views
How to implement DMG (Game boy) cpu's register using OOP patterns/principles to max code reusability?
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 ...
-1
votes
1
answer
93
views
How to solve inter-dependency of the composed class on it's property
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 ...
-3
votes
1
answer
2k
views
Is it a bad practice to pass instance as function parameter? [closed]
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 ...
2
votes
2
answers
656
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 ...
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, ...
1
vote
1
answer
446
views
C# how to implement a factory class which doesn't require an argument passed to indicate objects type?
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)
...
3
votes
5
answers
3k
views
Should validation logic be inside a factory method or inside the object's constructor?
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 ...
3
votes
1
answer
578
views
Builder that creates a repository for a specific entity - is this an established pattern?
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; ...
-2
votes
1
answer
539
views
Is there a proper way of implementing runtime control of dependencies using DI? Is factory pattern okay? [closed]
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 ...
-2
votes
1
answer
657
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 ...
1
vote
2
answers
2k
views
Is a python `abstract property` that returns an abstract class an example of the Factory Pattern?
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 ...
2
votes
0
answers
480
views
How to handle a bunch of nested ValueObjects?
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 ...
0
votes
2
answers
2k
views
Combining synchronous and asynchronous commands when using the command pattern
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 ...
3
votes
1
answer
580
views
Design Patterns: Factory Pattern Vs. getInstance Inside Abstract Class
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 ...