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
44 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 ...
user avatar
1 vote
3 answers
168 views

Abstract Factory Pattern Implementation

I implemented the Abstract Factory design pattern as follows. Concrete Implementation ...
user avatar
  • 165
18 votes
2 answers
2k 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 ...
user avatar
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 ...
user avatar
  • 331
0 votes
1 answer
110 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 ...
user avatar
  • 103
2 votes
1 answer
507 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 ...
user avatar
  • 121
2 votes
3 answers
125 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 ...
user avatar
2 votes
1 answer
81 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,...
user avatar
  • 45
4 votes
1 answer
541 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, ...
user avatar
  • 141
2 votes
1 answer
80 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 ...
user avatar
  • 21
0 votes
1 answer
103 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 ...
user avatar
  • 3
9 votes
0 answers
709 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 ...
user avatar
8 votes
1 answer
338 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 ...
user avatar
3 votes
1 answer
902 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 ...
user avatar
  • 33
2 votes
1 answer
104 views

Determine dependency injection type at runtime from config

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

Swift Struct-based Factory Pattern

Edit: I added another configuration vector to CardView, a size attribute, which may be .small or ...
user avatar
0 votes
1 answer
87 views

Is this implementation of factory design pattern in C#?

Here are my class library code which create credit card. ...
user avatar
4 votes
1 answer
383 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 ...
user avatar
  • 43
1 vote
1 answer
68 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. ...
user avatar
6 votes
1 answer
2k 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 ...
user avatar
  • 293
0 votes
1 answer
48 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 ...
user avatar
3 votes
1 answer
180 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 ...
user avatar
4 votes
1 answer
208 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 ...
user avatar
  • 43
5 votes
0 answers
172 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 ...
user avatar
  • 4,028
1 vote
1 answer
584 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: ...
user avatar
1 vote
1 answer
40 views

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

Consider this code: ...
user avatar
  • 273
5 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 ...
user avatar
0 votes
1 answer
115 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 ...
user avatar
  • 389
3 votes
1 answer
142 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 ...
user avatar
0 votes
2 answers
1k 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 ...
user avatar
  • 167
4 votes
1 answer
1k 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, ...
user avatar
  • 41
2 votes
2 answers
238 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: ...
user avatar
1 vote
2 answers
223 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. ...
user avatar
1 vote
2 answers
2k 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 ...
user avatar
  • 195
4 votes
0 answers
79 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 ...
user avatar
  • 307
1 vote
0 answers
23 views

Logs UI errors to a service provided in the configuration

As part of the project I am currently working on we want to log our UI component errors as well. I developed this package as a base. It's a factory (basically, not sure if it's correctly a factory). ...
user avatar
2 votes
1 answer
182 views

Factory Design Pattern in Java [closed]

I am currently attempting to understand the fundamentals of factory methods in Java and I found a lot of exampels where a pattern like this has been used. I got some exercises about sorting algorithms ...
user avatar
8 votes
4 answers
1k views

Packet Factory design for networking application

I'm working on a network application that implements a custom protocol. I want to easily extend the application support over the protocol as it changes. Also, as the application extends, I might need ...
user avatar
2 votes
0 answers
328 views

Show mobile SoundCloud player in WebView

Demo for a SoundCloud player in WebView for specific song or artist stream as a workaround because SoundCloud is not accepting API key request anymore. SoundCloudWebView: ...
user avatar
  • 91
6 votes
3 answers
2k views

Creating HTTP proxies for services

I have a HTTP client factory that creates a separate HTTP proxy instance for each of my services - which are in the cloud. The factory creates each instance on the basis of an interface which the ...
user avatar
1 vote
2 answers
73 views

JavaScript library to notify watchers of changes

Background Last year, while I was still entering the beginning of Immutability and Pure functions and whatnot I created a library for the community called ...
user avatar
5 votes
2 answers
188 views

Model-to-Prefab mapper and factory

I am creating a fluent interface to build user interfaces in the Unity game engine. As a subcomponent of this library, I have a set of objects called Components (e.g. Panel, Button, etc) that I want ...
user avatar
  • 5,167
7 votes
1 answer
2k views

Object-oriented calorie counter

Object-oriented program for a calorie counter sporting polymorphic methods for both genders. Principles to adhere to: Uniform Access Principle Polymorphism Dependency inversion principle through the ...
user avatar
  • 385
1 vote
3 answers
80 views

Choose betwen a few message values depending on 3 variables

This code write out the title and the body of a message depending basically on 3 variables combination. How could i refactor this nicely? a factory pattern? how more precisely? a mapping array ? but ...
user avatar
  • 121
2 votes
2 answers
7k views

Using Autofac to do DI in a static factory method

I'm using Autofac to create one of my classes inside of a static factory method Create. This code is working and I haven't noticed any side effects yet. Admittedly, ...
user avatar
  • 43.8k
1 vote
0 answers
34 views

Factory method to make JSON requests for various types of list items

I have the following code: ...
user avatar
1 vote
1 answer
835 views

utility class for reading in JSON

I'm reasonably happy with the execution: ...
user avatar
  • 389
2 votes
1 answer
360 views

Rendering SharePoint lists into tables with any number of columns

I have the following code, but first the explanation. I am using a REACTJS Office UI Component called details list: https://developer.microsoft.com/en-us/fabric#/components/detailslist And I want my ...
user avatar
1 vote
2 answers
255 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 ...
user avatar
1 vote
0 answers
58 views

Creating objects by defined name

I'm trying to write universal factory creating objects by name. I've got some working prototype now but there must be a better way than casting construction methods to void pointer. ...
user avatar
  • 13