As of May 31, 2023, we have updated our Code of Conduct.

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
3 answers
81 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 ...
Matoeil's user avatar
  • 121
2 votes
2 answers
8k 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, ...
t3chb0t's user avatar
  • 44k
1 vote
1 answer
935 views

utility class for reading in JSON

I'm reasonably happy with the execution: ...
Thufir's user avatar
  • 379
2 votes
1 answer
365 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 ...
Luis Valencia's user avatar
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 ...
Ryan Caskey's user avatar
1 vote
0 answers
60 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. ...
Travis's user avatar
  • 13
0 votes
1 answer
5k views

A factory with static objects or an enum with instance objects?

My application accepts different messages. A message is described by its schema. enum ...
Sam's user avatar
  • 179
0 votes
2 answers
96 views

Class-based Message System Pattern

I'm trying to create an extensible system for building messages. I want each style of message to be a unique class. I don't want the client to have to worry about the class type when creating the ...
David's user avatar
  • 361
1 vote
2 answers
2k views

Correct implementation of the factory pattern in php

All, during my vacation I am trying to learn myself the basic principles of OOP and the factory pattern in php. I read a lot of tutorials and websites (e.g. http://www.phptherightway.com) and began to ...
CasperHobs's user avatar
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 ...
Daniel Ryan's user avatar
6 votes
1 answer
56 views

ItemFactory Class - Creates copies of predefined items by name and returns by pointer

I'm working on writing a text based RPG game, and I've decided to define each possible item as a JSON file in a specific directory. The item factory is meant to act as a singleton, and uses static ...
HSchmale's user avatar
  • 875
2 votes
1 answer
661 views

DDD Domain Objects, Factories, and Presenters

Aloha, I am working to understand some of the different pieces of domain driven design. In this particular case, I have a NameFactory that builds a Name domain object. I also have a NamePresenter ...
joel's user avatar
  • 31
0 votes
2 answers
162 views

PDO anonymous function inside a Factory

In this question here on S.O, the accepted answer suggests to use both anonymous function and factory pattern for dealing with PDO connection. I believe the anonymous function is used in case a ...
feetnappy's user avatar
  • 125
2 votes
0 answers
609 views

Simple files parsing and info extraction

First let me describe the problem, we want to solve: We have hierarchical directories structure with different types of templates. Each type of templates is located in dedicated folder. Hierarchical ...
Jevgenij Nekrasov's user avatar
1 vote
2 answers
435 views

Factory design pattern with Shapes

I'm making the very common example of Factory design pattern which creates a factory of shapes and return an instance of the type Shape. I wonder which is the best way to replace that bunch of nested ...
Sandoval0992's user avatar
1 vote
1 answer
116 views

"Factory" which produces a "connection" object

I am a newbie in C# and in OOP in general. I decided to create a class that should give out a "connection" object. I would like your advice and critique on improving it. ...
Gordon Freeman's user avatar
2 votes
1 answer
222 views

Factory design pattern for circles and polygons

I am going over a number of design patterns and today I ask you to please inspect my application attempt of the Factory design pattern. Please feel free to share what you think about it, because my ...
TradingDerivatives.eu's user avatar
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 ...
ovidiu-miu's user avatar
3 votes
1 answer
611 views

Generating Settings Objects from Database via Factory Class

In an ASP.NET MVC application (C#) have a factory-like class that generates settings objects of ISettingType for my application. However, some settings are very ...
JNYRanger's user avatar
  • 133
4 votes
4 answers
196 views

Factory Method Pattern - Base implementation to Add New Records

Most importantly which bothers me in the following implementation is the call in BranchAddManager, do I really need to call ...
Coder Absolute's user avatar
4 votes
2 answers
259 views

Factory for report handlers

Below is my try. ...
Kgn-web's user avatar
  • 161
1 vote
1 answer
432 views

Factory to create Finite Impulse Response filters in C++

I've recently begun a project in digital signal processing and am using C++ as the programming language. In this project, I have implemented several finite impulse response (FIR) filters. Many of ...
Izzo's user avatar
  • 113
3 votes
2 answers
4k views

Window Factory and Manager using MVVM pattern

I am fairly new to Factories and Dependency Injection in MVVM. I've build my View(Window) factory with help from SO, and I would like to know if I had implemented everything properly(code works just ...
Kamil Solecki's user avatar
6 votes
2 answers
1k views

Python REST API clients

I am working on a project right now, where we need to search different APIs, then clean & persists data to database and finally pushing to Elasticsearch. The high level code looks like this: <...
Alex benz's user avatar
  • 113
3 votes
2 answers
116 views

Sequence generators not only for potatoes but also for apples and oranges

The last question about sequence generators Growing potatoes in delayed sequences was only about potatoes. I thougt why not make it work with apples and oranges too so I made it generic. The base ...
t3chb0t's user avatar
  • 44k
1 vote
1 answer
99 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 ...
andrius.k's user avatar
  • 141
2 votes
2 answers
1k views

SQL Prepared Statement Factory

I have written a simple prepared statement factory in Java and would like some feedback on how "secure" it is. By "secure" I mean that I can pass any old garbage in as a string and it should not allow ...
Jack Wilsdon's user avatar
  • 1,641
6 votes
2 answers
489 views

Simple factory pattern for cooking a pizza

I have developed a command line application which prompts the user to initially select an oven and then requests that they cook a pizza. The oven affects the pizzas cooking time. The pizzas ...
ExohJosh's user avatar
  • 163
2 votes
1 answer
112 views

Object publisher factory

I have an IPublisherFactory which publishes instances of, IPublishers. I'm feeding it a bunch of overloaded methods from this gigantic class, that I'm basically using for organization of the ...
Nathvi's user avatar
  • 188
1 vote
2 answers
983 views

Implementation of Factory Method pattern for XML and Excel documents

I started learning factory pattern, and also implemented factory method pattern. My factory-method pattern classes are as follows: There are two major parts, an interface "Document.java" and and ...
Rahul Shivsharan's user avatar
2 votes
0 answers
499 views

Factory (pattern) of Commands (pattern) with additional dependency injection (dependency inversion pattern)

What would you improve at the following code, except: The problems I'm already aware of, marked as TODO Line width of at most 120 characters (I've run flake8 over ...
Flavius's user avatar
  • 129
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. ...
Antonin Cezard's user avatar
4 votes
0 answers
210 views

Extensible factory method for starting D3 charts

I'm working on refactoring some existing code to be a bit more extensible and am wanting to create a generic factory API for starting D3 charts. Currently, my factory looks like this: ...
aendra's user avatar
  • 141
12 votes
3 answers
6k views

Building car factory with custom features per car

I was once asked in an interview to build a factory that makes cars. All cars has common features like price, rating and color and they have some features like fuel injection which can on specific car ...
Ziv Weissman's user avatar
4 votes
1 answer
64 views

Factory to augment JS classes with validation methods

I have some validation classes. To keep things smooth, I create a single class that has those validation classes inside of it. That class will be a singleton, and gets injected into my other classes. ...
Randy's user avatar
  • 302
2 votes
1 answer
189 views

Factory method that constructs objects that represents MySQL data types from query results

I'm writing a package that is designed to provide a convenient way to inspect the schema for a database. The goal is that I can use it for generator code to suit the schema. The complete code can be ...
Courtney Miles's user avatar
11 votes
2 answers
705 views

Beep-beep I'm a car factory

I have implemented to following generic factory in C++11 using smart pointers and I would like to get some feedback about it. (Please note that I can't use C++14) Due to company policies I have to ...
user695652's user avatar
3 votes
1 answer
939 views

Extending functionality of org.springframework.batch.item.file.transform.DefaultFieldSet

I would like to be able to set token values (defaultFieldSet.tokens) and names (defaultFieldSet.names) on ...
James's user avatar
  • 299
1 vote
1 answer
59 views

Factory that Creates Reusable Class Builders for a Racing App

In a project for fun/practice, I made a few builder classes that all started to feel the same, so I decided to generalize them by creating a factory that would automatically assign the similarities ...
Joshua Dawson's user avatar
6 votes
1 answer
117 views

Extendable JavaScript module that converts between camelCase, PascalCase, and underscore_case

The basic idea is that by defining three functions--recognize, dissect, and combine--...
Joshua Dawson's user avatar
4 votes
2 answers
2k views

Angular notification (alert) factory or directive

I am new to AngularJS and I thought of trying something simple: a notification factory that is useful for displaying actions alert messages like "Save successfully!" or "Validation errors: ...". The ...
Alexei's user avatar
  • 1,786
2 votes
2 answers
77 views

Instantiating different kinds of error records for a database operation

I've written code to be called from Powershell like so: Rename-DatabaseUser -Name 'someuser' -NewName 'somenewuser' I'm wondering if there's another way I can ...
Jake's user avatar
  • 131
1 vote
2 answers
2k views

Instantiating shapes using the Factory Design Pattern in Java

Trying to learn the factory design pattern, came up with some code based on a Shape Factory (found this example here). Is this the right way to implement the factory pattern? ...
DontForgetTheSemiColon's user avatar
2 votes
3 answers
80 views

Factory to construct a FineTime out of many kinds of objects

Any suggestions to help refactor this method? I thought maybe some kind of factory to allocate the right type? ...
user1472672's user avatar
2 votes
1 answer
298 views

Generating sample data for a Rails application

I am working on generating sample data for my Rails application. For now we will just be using the sample data while we are designing the website. I'd like it to be as easy as possible to generate ...
Amanda Dolan's user avatar
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 ...
Cilyan's user avatar
  • 285
7 votes
1 answer
3k views

Compile-time plugin system

Background For a piece of software that I need to get extensible, I wanted to design a simple compile-time "plugin" system in C++. My use case was that the program (actually a library) can accept ...
Cilyan's user avatar
  • 285
0 votes
1 answer
63 views

Selecting control class in a document assembler

I feel like there is a cleaner/simpler way of doing the following. Is there an existing software pattern that I should be using? I have an Assembler class that I ...
Matt Fitzmaurice's user avatar
3 votes
1 answer
386 views

Factory pattern in F# for a web scraper

I'm trying to learn F# by creating a little web scraper that will do custom scraping based on the url domain. For this, I need to create and select the correct kind of scraper. I figure I would use a ...
ceiling cat's user avatar
3 votes
1 answer
107 views

Creating a lightweight strongly-typed parameter infrastructure

I'm looking for some feedback on some code, designed to allow me to strongly-type parameters, which get passed to functions. I'm only really looking for comments on making my parameters more strongly ...
askrich's user avatar
  • 175