Skip to main content

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
21 votes
2 answers
5k 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 ...
Thingamabobs's 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 ...
Giogre's user avatar
  • 331
13 votes
2 answers
159 views

"Drone Racer" now shipping in your local area

This question is a follow-up of this one; where I present a software to plan and manage drone races. I might come with a new question about the SQL part in a few days as well. The code can still be ...
301_Moved_Permanently's user avatar
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
11 votes
2 answers
707 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
10 votes
3 answers
677 views

Is this correct factory method pattern?

I know that there are many similar questions, but I don't understand most of those questions because I'm not sure if I know what a factory method pattern is. So, after reading many examples over the ...
Moon's user avatar
  • 378
10 votes
3 answers
6k 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 ...
Blue7's user avatar
  • 373
10 votes
1 answer
89 views

Methods creating transform functionality on Collections

I have written a few simple-to-be-used methods in Java 8, and am wondering what could be improved upon those: ...
skiwi's user avatar
  • 10.6k
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 ...
Cristian Buse's user avatar
9 votes
4 answers
5k views

Creating unique registration numbers using object factories

I'm learning about immutability and uniqueness in Java, particularly the use of defensive programming and object factories. I have been asked to create a class containing an object factory that when ...
javapalava's user avatar
9 votes
5 answers
10k 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
9 votes
4 answers
38k views

Using std::unique_ptr and std::move

I'm trying out new things (on class Inproc), specifically using std::unique_ptr and std::move...
Goswin von Brederlow's user avatar
9 votes
2 answers
3k views

Is this a good implementation of the Factory Pattern?

Suppose I have this code: ...
user avatar
8 votes
2 answers
2k views

Factory Method implementation

Can you please verify my approach? ...
Thava's user avatar
  • 83
8 votes
4 answers
2k 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 ...
Cosain Melic's user avatar
8 votes
1 answer
526 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 ...
Cristian Buse's user avatar
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 ...
kluvin's user avatar
  • 385
7 votes
1 answer
4k 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
7 votes
1 answer
415 views

Polymorphic TLV serialization

Inspired by this question I decided to write an alternative that uses polymorhphism and a Factory pattern. The code works for the subset of implemented types, namely ...
Edward's user avatar
  • 66.4k
7 votes
1 answer
2k views

C++11 Logging Architecture

To create a Logging system for a larger application, I came up with the following draft. The log sinks aren't detailed yet, but the factory method for logger creation and a rough draft of the logger ...
Martin's user avatar
  • 171
7 votes
1 answer
2k views

Factory design for math problems

I'm creating a factory design for math problems. The idea which I have is: When the factory initializes, creates in a list some problems (20 initially) If the program wants more than 20, the list ...
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 ...
Alternatex's user avatar
6 votes
3 answers
7k 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 ...
Yashi Srivastava's user avatar
6 votes
4 answers
1k views

Simple factory retrieving object by name [closed]

Despite the fact that this code works, I would like to know if there's any situation I did not anticipated, and/or if what I am trying to do is some what wrong. -std=C++11 flag needed ...
Rafael Fontes's user avatar
6 votes
2 answers
516 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
6 votes
1 answer
104 views

Is this a fair use for a factory pattern?

...
user46957's user avatar
6 votes
1 answer
258 views

Use of static factory methods for vectors and matrices library

I've been working on a Java-based mathematics library focusing on vectors and matrices. I plan to use it for an important upcoming project, so the classes are analogous to data types available in GLSL ...
code_dredd's user avatar
6 votes
2 answers
238 views

Abstract Factory Experiment

While I should probably be using Dependency Injection via Ninject or a similar project, I have been attempting to implement an abstract factory design that would provide me with the following easy to ...
jmsb's user avatar
  • 223
6 votes
2 answers
2k views

Is this a correct way to use Factory Pattern?

I have an abstract class which implements the IDataCreator interface: ...
sk2212's user avatar
  • 185
6 votes
1 answer
1k views

Factory template method for generalized functors

(A quick note on terminology: I use 'generalized functor' to refer to a functor that can be initialized from any callable entity, similar to the definition from Alexandrescu's Modern C++ Design. I use ...
Daan's user avatar
  • 526
6 votes
1 answer
229 views

Universal Spreadsheet reader/writer

I have a project that reads spreadsheets as a rectangular list of lists (matrix) transforms the matrix and then writes it to another spreadsheet. I want to be able to read from and write to multiple ...
cheezsteak's user avatar
  • 2,401
6 votes
1 answer
57 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
  • 895
6 votes
1 answer
213 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
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
6 votes
1 answer
121 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
5 votes
1 answer
226 views

Message factory

Today I thought about Factory Design Pattern in Swift, and I do an implementation with Extension. My post is about if anyone have any observation or issue about this implementation violate any ...
ViTUu's user avatar
  • 239
5 votes
2 answers
10k views

Java implementation of the Factory Method pattern

I am working on a very simple game and thought it would be a good opportunity to learn and use the Factory Method pattern for creating game objects. I studied the pattern but I'm a bit confused about ...
Shijima's user avatar
  • 387
5 votes
2 answers
196 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 ...
Nick Udell's user avatar
  • 5,197
5 votes
1 answer
371 views

Create Java object from from page content or plain text

My job is to make a specified java objects from web page that contains following text: Companies: ...
dagi12's user avatar
  • 277
5 votes
1 answer
351 views

Python factory method with easy registry

My aim is to define a set of classes, each providing methods for comparing a particular type of file. My idea is to use some kind of factory method to instantiate the class based upon a string, which ...
David Hall's user avatar
5 votes
2 answers
153 views

Naming Vegetable Factories

Given the code below, I'm curious to know if you'd have better naming suggestions for types: VegetablePresentersFactory ...
spg's user avatar
  • 151
5 votes
1 answer
245 views

Abstract factory or inversion of control pattern?

I have several generic methods that use the typeof operator to determine the type of mapper class to create. Eventually this is going to get out of hand. Can ...
user2608193's user avatar
5 votes
1 answer
180 views

Anonymous methods, factory methods, threading, and XML input

I have an application which retrieves data from a (potentially) very large XML file. A combination of XMLReader and XDocument seemed to be the only way I could manage the entire thing the way I ...
Mason11987's user avatar
5 votes
1 answer
1k 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, ...
Seamus's user avatar
  • 151
5 votes
1 answer
1k views

Using $q in Angular JS to pass navigator geo JSON from factory to controller

This code is used to get the users location and deliver it as a resource to the controller. The aim is to have this data shared across multiple controllers in the application. So far this does deliver ...
zia grosvenor's user avatar
5 votes
0 answers
257 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 ...
TinMan's user avatar
  • 4,143
4 votes
2 answers
1k views

"Fancy-pants" vs "Cowboy" coding [closed]

Based on the post I made here: RFC on "Factory" code and its responses, and my (inner) response to those responses, I'm beginning to wonder if it would be just as well to simply switch based ...
4 votes
2 answers
278 views

Factory for report handlers

Below is my try. ...
Kgn-web's user avatar
  • 161
4 votes
4 answers
199 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
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 ...
rechandler's user avatar