Questions tagged [factory-method]
Use this tag for code reviews of, or involving methods that create a new instance of a given type, often with parameters that determine how the instance gets created.
155 questions
5votes
1answer
352views
Trying Out DDD : How to enforce data integrity and immutability
I've been transitioning from type-safe programming languages like Dart and Java to Python, and I'm trying to enforce Domain-Driven Design (DDD) principles in a language that naturally leans towards ...
3votes
1answer
87views
C++17 static inline member variables to populate factory at static initialization time
The Context I have a toy ECS architecture where I want to serialize and deserialize the whole app state for hot-reloading DLLs. I don't want the user to have to register all components at the ...
2votes
1answer
405views
Factory pattern with variadic constructor
I have this code for a factory design pattern that will take into account any number of arguments in the constructor. Through a static boolean in the class a ...
2votes
1answer
71views
Creating multiple conditions in objects preventing nesting
My class is a factory-method that allows to instantiate it only when the parameter $type (string) is "regular or premium" and when parameter $months (integer) is lower than 6. If $months is ...
2votes
1answer
76views
Factory for state classes with varying numbers of reference data members
Consider the following code: ...
1vote
1answer
111views
Web scraper for e-commerce sites Part II
I asked the same question Web scraper for e-commerce sites yesterday and I'm now posting the revised code here. I'm building web scraper application which takes name, code and price from few sites. I ...
0votes
1answer
201views
Web scraper for e-commerce sites
I'm building web scraper application which takes name, code and price from few sites. I thought factory pattern would fit in my application. I would like to someone review my code and tell if I ...
4votes
2answers
150views
Abstract Factory Implementation C#
I'm learning Factory pattern and I've implemented this simple example of an abstract factory. I've followed this video a little bit while writing this small example. Is there anything anti-pattern or ...
2votes
1answer
369views
Dart Ioc Container
This package is on pub dev here It's on Github here ...
1vote
1answer
72views
Handling resource authorization in a service
Problem: My application is built upon clean architecture. I want to create a new instance of a class in my lower layer, but the class itself resides in an upper layer. The upper layer can depend on ...
1vote
3answers
191views
Abstract Factory Pattern Implementation
I implemented the Abstract Factory design pattern as follows. Concrete Implementation ...
21votes
2answers
5kviews
Python - Tkinter - periodic table of chemical elements
Inspired by a question on StackOverflow I decided to code a GUI that is simple, efficent and can be used in other projects as well. I wanted to share this code since it probably is usefull to other ...
14votes
4answers
2kviews
Numerical integration in C++: Newton-Cotes formulas
I have tried my hand with implementing simple quadrature formulas in C++. Definite integral: $$\int_a^b f(x) dx$$ Domain of integration \$[a, b]\$ divided into \$n\$ intervals of equal length \$h = (b ...
0votes
1answer
430views
Factory pattern to build multiple models
I have used the factory pattern for one of my projects. I want to know if this is a good design or if my code can be improved to make it as fast as possible. I am not an expert in C#. This is what I ...
2votes
1answer
3kviews
Factory pattern using enum
I wanted to have a factory-method, but without the if statements that are often seen in examples of this pattern. So I came up with this, and would like to know: is ...