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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
59 views

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 ...
14 votes
4 answers
2k views

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 ...
2 votes
1 answer
55 views

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 ...
2 votes
1 answer
61 views

Factory for state classes with varying numbers of reference data members

Consider the following code: ...
4 votes
1 answer
943 views

Python factory class with dynamic imports

I'm trying to write a factory class that essentially provides a user-friendly frontend to creating objects of different kinds depending on keywords. So the user will just have to import this module, ...
1 vote
1 answer
91 views

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 ...
0 votes
1 answer
133 views

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 ...
21 votes
2 answers
3k views

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 ...
4 votes
2 answers
130 views

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 ...
10 votes
3 answers
4k views

C++ Template to implement the Factory Pattern

Design A template class that will create a concrete instance of an interface class when given the name (as a string) of the concrete class. This design is often seen in code, so the purpose of this ...
9 votes
5 answers
9k views

Instantiating a C++ class based on an enum value

I have a bit of code duplication and trying to figure a better way to reduce it. I'm looking for any suggestions. If this was in Java I could easily use reflection. The code posted is a basic ...
6 votes
1 answer
209 views

2d game enemy entities factories, probably in need of refactoring

So I'm making a 2d shoot'em up game as a way of learning canvas, and larger-scale programming than what I'm accustomed to. I'm a purely front-end web dev, I can't say I'm very experienced in this. ...
2 votes
1 answer
313 views

Dart Ioc Container

This package is on pub dev here It's on Github here ...
1 vote
3 answers
187 views

Abstract Factory Pattern Implementation

I implemented the Abstract Factory design pattern as follows. Concrete Implementation ...
1 vote
1 answer
59 views

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 ...
0 votes
1 answer
195 views

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 ...
2 votes
1 answer
2k views

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 ...
4 votes
0 answers
571 views

Compile-time plugin system (2)

Background This is a follow-up of this CR: Compile-time plugin system. The code exposed below can also be browsed on this gist, which shows the differences between both questions (original is version ...
2 votes
3 answers
271 views

Factory Method Design Pattern Implementation as a Coffee maker program

File: InfoFactory.h contains four classes. CaffienatedBeverage is an Abstract class with one pure virtual function Name. It ...
2 votes
1 answer
116 views

Scrape multiple twitch IRC chats

I've always struggled to create and sustainable, organizated, clean code. I tried to use a Factory method and it's working better now that I created another class. I know I should write documentation,...
4 votes
1 answer
2k views

Factory pattern with controls

I've created factory to create WPF controls. I have string with control name and I map it to enum. I think it's bad implementation of factory pattern. So please show me where I've made mistake. Main ...
10 votes
0 answers
1k views

Private VBA Class Initializer called from Factory #2

About This is a follow-up of a previous question Private VBA Class Initializer called from Factory. I've decided to create a new question instead of answering my old question because I would like the ...
2 votes
1 answer
92 views

Factory Method and Log writer class

I Have this class want to practice how to write a factory method pattern and I can change the logPlace by set the app.config, and I try to improve the performance ...
0 votes
1 answer
123 views

Best practice for factory pattern in c++?

I'm implementing a simple data reader to get image sequences from either a pre-recorded video file (In my case ROS bag file), or a camera device (In my case Intel Realsense). Basically I intend for ...
8 votes
1 answer
454 views

Private VBA Class Initializer called from Factory

I've been playing with COM lately and while getting to understand the mechanism of how class methods/properties are called an idea came to mind: what if we can have a global instance of a class that ...
3 votes
1 answer
2k views

Implement Factory pattern with multiple parameters and each parameters are interface

I am a little bit confused on Factory Method with multiple parameters in which all parameters can change from GUI by user as seen below picture. For each combobox item I have an interface and ...
2 votes
1 answer
182 views

Determine dependency injection type at runtime from config

I have a .NET application with a .config file that has content like this: ...
2 votes
0 answers
222 views

Swift Struct-based Factory Pattern

Edit: I added another configuration vector to CardView, a size attribute, which may be .small or ...
4 votes
1 answer
559 views

Bank with factory method for accounts, multithreaded deposit and withdraw

I have a couple questions about this program Should I implement runnable instead of using thread class? I like the idea of the consumer and producer being thread objects, it seems simpler to me, but ...
0 votes
1 answer
106 views

Is this implementation of factory design pattern in C#?

Here are my class library code which create credit card. ...
1 vote
1 answer
71 views

Using a factory pattern many times [closed]

This is my first question on this website and I hope it goes well. I have created a Kotlin factory pattern and I am using it very frequently. the code I use it consists of functions inside a class. ...
2 votes
2 answers
359 views

PHP Factory Pattern : Should I use `create()` or `__invoke()`?

I currently had a colleague reviewing my code and he had a comment on a factory class I created. It's very simple: ...
4 votes
1 answer
2k views

Electricity billing system for home in OOP

I recently appeared for interview for code-pairing round and I was asked following question: Electricity Billing System for home. The corresponding power usage of home appliances (Fan, AC, Fridge, ...
1 vote
1 answer
100 views

Factory hierarchy for creating GoogleMap and its elements

The purpose of this code is to create a GoogleMap using PHP, add markers to it according to Place objects from database, add infoWindows for these markers. While ...
0 votes
1 answer
52 views

Use of Factory pattern — how to implement it

I am trying to figure out how Factory pattern works. I implemented it with TypeScript in this github repo: https://github.com/emilecollin/factory_pattern Basically this is emulating spaceships gaming ...
3 votes
1 answer
192 views

Grouping low-level services together into a high-level service

I am working on an e-commerce website. What I need to do is to save an advertisement. The ad has some properties and some photos... properties should be save to DB and photos should be saved to file ...
4 votes
1 answer
267 views

Java enum-based factory to calculate entry parameters

I want to create a factory to return all Source instances that match given entry parameters- that is, I want to iterate through some Collection of objects and for each entry check boolean method. I ...
5 votes
0 answers
198 views

Factory class that uses reflection to instantiate objects by class name

In this SO post Dynamically choose class from string Alexander Platonov creates a Function on the fly and then uses Application.Run() to instantiate an Object by ...
1 vote
1 answer
1k views

Creating a ModelBinder to Sanitize user input in HTML format

I have a custom model binder which takes user input in HTML format, sanitize the HTML input by removing any script or XSS threat and returns the sanitized HTML string: ...
6 votes
3 answers
6k views

Chess move validator

I have written code for making a Chess Validator, which will validate the moves of a chess game. There is a Main class which is taking the input from the user, about the move. Problem Description ...
1 vote
1 answer
42 views

Create a pump object from either one of pump model number or pump product id

Consider this code: ...
4 votes
2 answers
67 views

Configuring an editor for various languages using Factory Method Pattern

I need to know if my code is a valid implementation of the factory method pattern. Also, if the Configuration and Editor were interfaces would this still be a valid implementation of the Factory ...
1 vote
2 answers
227 views

Synchronizer for importing XML files into a database when folder content changes

I have created a Synchronizer, the purpose of which is to read data from an XML source file and store the result in a DB. I have different source types, for example Student.XML, School.XML, etc. ...
1 vote
2 answers
263 views

Two similar factory classes to instantiate services

I'm working on building a library to help you bootstrap the development of a Java API. The premise is, you can have your controllers implement interfaces like ...
0 votes
1 answer
124 views

Factory to instantiate and configure Selenium WebDriver

I, also, need to know whether this is a valid implementation of the factory pattern. The amount of effort which goes into configuring DriverFactory to simply get a ...
3 votes
1 answer
157 views

Instantiating View Models using a static factory

I am building an e-commerce website. I have an application layer service called SearchService. SearchService receives a search ...
0 votes
2 answers
2k views

Factory method to create two kinds of cars based on an enum

I am implementing the factory method approach. My intention is to know if my approach is correct for factory method. Any modifications to be done to align with the approach? First I am creating an ...
1 vote
2 answers
3k views

Shape area calculation

I know questions with this text has been asked and already answered, but my question is mainly limited to only one method of this flow and where it should be. I have an assembly for Shape's area ...
4 votes
0 answers
83 views

Chained Factories by Expression Template

I want to make factories that can chained together to create a pile of layers. One of the advantage of chained factories is that later factories can pass specifications to earlier factories. For ...
3 votes
4 answers
4k views

Avoiding Duplicates in a Ruby on Rails Factory Girl Factory with Fake

I have a Factory Girl factory that needs to generate a unique name using Faker. Unfortunately, Factory Girl generates duplicates relatively frequently, which causes intermittent test errors. I ...