The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
12
votes
3answers
5k 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 ...
11
votes
2answers
688 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 ...
11
votes
2answers
128 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 ...
10
votes
3answers
642 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 ...
10
votes
1answer
87 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: ...
9
votes
4answers
4k 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 ...
9
votes
4answers
31k 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...
9
votes
2answers
3k views

Is this a good implementation of the Factory Pattern?

Suppose I have this code: ...
8
votes
4answers
622 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 ...
7
votes
4answers
4k 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 ...
7
votes
2answers
1k views

Factory Method implementation

Can you please verify my approach? ...
7
votes
1answer
1k 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 ...
7
votes
1answer
1k 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 ...
7
votes
1answer
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 ...
7
votes
1answer
2k 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 ...
6
votes
3answers
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 ...
6
votes
4answers
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 ...
6
votes
2answers
352 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 ...
6
votes
2answers
166 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 ...
6
votes
1answer
101 views

Is this a fair use for a factory pattern?

...
6
votes
1answer
198 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 ...
6
votes
2answers
210 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 ...
6
votes
1answer
258 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 ...
6
votes
1answer
884 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 ...
6
votes
1answer
202 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 ...
6
votes
1answer
49 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 ...
6
votes
2answers
923 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: <...
6
votes
1answer
102 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--...
5
votes
3answers
718 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 ...
5
votes
1answer
212 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 ...
5
votes
1answer
197 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 ...
5
votes
2answers
143 views

Naming Vegetable Factories

Given the code below, I'm curious to know if you'd have better naming suggestions for types: VegetablePresentersFactory ...
5
votes
2answers
1k views

Is this a correct way to use Factory Pattern?

I have an abstract class which implements the IDataCreator interface: ...
5
votes
1answer
235 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 ...
5
votes
1answer
152 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 ...
5
votes
1answer
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 ...
5
votes
0answers
104 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 ...
4
votes
2answers
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
2answers
170 views

Factory for report handlers

Below is my try. ...
4
votes
2answers
9k 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 ...
4
votes
4answers
184 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 ...
4
votes
1answer
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 ...
4
votes
2answers
59 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 ...
4
votes
1answer
160 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: ...
4
votes
1answer
8k views

Best way to write generic factory in Java

I need to write a factory of generic converters to produce converters from/to MongoDB objects to/from Java objects. Here is my implementation, it doesn't look good enough to me, so I would like to see ...
4
votes
1answer
3k views

Are there side-effects to having a generic Ninject factory?

Consider this class: ...
4
votes
2answers
1k 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 ...
4
votes
2answers
86 views

Simple Translation Gem

I have a small gem that I've been maintaining. This gem provides a simple way to do translation using an alternative Google API. I've been working with Java last year and recently did some ...
4
votes
1answer
72 views

Code for simplifying the creation of Dimension Objects

I have a class that I use to represent a distance called Dimension. Here is its four constructors: ...
4
votes
1answer
100 views

Does the class have unnecessary and violating Single responsibility principle method?

I encountered with the following code in the work. The MyItemCoordinator should receive MyItem objects, process them, add them ...