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
1answer
98 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 ...
1
vote
2answers
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 ...
6
votes
2answers
365 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 ...
2
votes
1answer
102 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 ...
1
vote
2answers
752 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 ...
2
votes
0answers
458 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 ...
4
votes
0answers
151 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. ...
4
votes
0answers
143 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: ...
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 ...
3
votes
1answer
54 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. ...
2
votes
1answer
145 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 ...
11
votes
2answers
689 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 ...
3
votes
1answer
620 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 ...
1
vote
1answer
51 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 ...
6
votes
1answer
104 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--...
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 ...
2
votes
2answers
68 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 ...
1
vote
2answers
1k 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? ...
2
votes
3answers
78 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? ...
2
votes
1answer
203 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 ...
2
votes
0answers
344 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 ...
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 ...
0
votes
1answer
59 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 ...
3
votes
1answer
317 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 ...
3
votes
1answer
99 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 ...
12
votes
2answers
132 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 ...
6
votes
1answer
263 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
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 ...
3
votes
0answers
120 views

Angular OOP services and caching

I've created a caching service using OOP techniques combined with the revealing module pattern and the angular-cache library. New CacheDataClass objects are ...
3
votes
0answers
181 views

Threadsafe singleton factory to use in Apache thrift server RPC system

My goal was to write a factory that the code did not have to be edited. Thus I am registering my factory functions into a singleton factory. I am going to be using this code in Apache thrift server ...
3
votes
1answer
1k views

Enforce what is passed to an activity in an intent similar to the newInstance pattern for fragments

For fragments I have this code to create a new instance: ...
4
votes
2answers
87 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
177 views

Factory that creates a complex object tree

I've got a complex object tree that I need to instantiate. The object tree is a bunch of specialized classes that don't have a common root object (other than Object) and has generic objects (that I ...
2
votes
1answer
176 views

Workflow class with Start(), Continue(), and Resume() methods

I have a session class that needs to be setup based on different needs of the client code. Sometimes a new session needs to be created, or continued, or resumed (loaded from database after a user has ...
1
vote
1answer
63 views

Interfaces & Factory for generic container supporting PeekMax, PeekMin, Sum, and PeekNextToMax

This is a partial update of this question. An implementation of these interfaces is in this question. To summarize, the class is a generic container similar to MaxHeap, but only needs to support the ...
1
vote
1answer
326 views

Factory dependency injector

I recently made the switch from procedural to OOP style of coding. I decided I wanted to learn how everything works before deciding to jump into a framework, follow tutorials, and becoming dependent ...
3
votes
1answer
2k views

Singleton base class

I just wrote a singleton base class for a hobby project I'm currently working on. Python is not my first language, which is why I am not sure if everything is done the pythonic way. I also used ...
4
votes
1answer
163 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: ...
5
votes
1answer
203 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 ...
2
votes
1answer
2k views

Replacing IUnitOfWork with a Factory Pattern

As a follow-up to this blog post and this question, I wanted to post my idea of replacing the IUnitOfWork with a factory pattern. It seems to me that in the case of this blog post the IUnitOfWork ...
5
votes
1answer
213 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 ...
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 ...
2
votes
1answer
1k views

Implementation of MVC Bootstrap & Factory

Before I get started, I feel I need to list the following. I am not looking for an existing DI or Framework this is a personal project to shift from procedural to oop programming. Tear this apart. I ...
6
votes
1answer
200 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 ...
3
votes
1answer
96 views

Using one service ($http) on all the controllers

I have recently started working on angular.js and I like it. I have decided to use a single controller per view. I use the json data from the backend. As my work is progressing, my codes are getting ...
1
vote
1answer
289 views

PHP Factory Method Pattern Implementation

This is an attempt at the Factory Method Pattern It emulates the logical model and also the physical model Resources: http://en.wikipedia.org/wiki/Factory_method_pattern http://msdn.microsoft....
0
votes
1answer
163 views

Factory Pattern Implementation in PHP [closed]

I have read some articles regarding the factory pattern and decided to write some code as an exercise. This is my first attempt and am not 100% if I did it right. I've omitted some implementations for ...
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 ...
6
votes
1answer
926 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 ...
2
votes
4answers
3k 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 ...