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
7 votes
1 answer
388 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
  • 65k
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
3 votes
0 answers
132 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 ...
br3w5's user avatar
  • 255
3 votes
0 answers
215 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 ...
user249806's user avatar
3 votes
1 answer
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: ...
Ersen Osman's user avatar
4 votes
2 answers
100 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 ...
Cristian Oliveira's user avatar
4 votes
1 answer
238 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 ...
Alex Q's user avatar
  • 141
2 votes
1 answer
189 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 ...
programmer's user avatar
1 vote
1 answer
67 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 ...
Snowbody's user avatar
  • 8,432
1 vote
1 answer
375 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 ...
ICJ's user avatar
  • 109
3 votes
1 answer
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 ...
linluk's user avatar
  • 315
5 votes
1 answer
322 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
320 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
2 votes
1 answer
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 ...
MplsAmigo's user avatar
  • 121
5 votes
1 answer
224 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
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
2 votes
1 answer
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 ...
ICJ's user avatar
  • 171
6 votes
1 answer
246 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
3 votes
1 answer
99 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 ...
Thomas Sebastian's user avatar
1 vote
1 answer
328 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....
Robert's user avatar
  • 177
0 votes
1 answer
171 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 ...
Robert's user avatar
  • 177
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
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
3 votes
4 answers
4k 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 ...
Dan Kohn's user avatar
  • 845
9 votes
4 answers
36k 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
3 votes
1 answer
1k views

Is there a better design pattern for a SDK?

At work I decided it would be better to reverse engineer a SDK for one of our pieces of hardware. Because it is work related I can't share the exact code.. but I can give enough of a gist of the code ...
Robert Snyder's user avatar
1 vote
1 answer
96 views

Factory object with a dependency on a bean

My problem is quite straightforward. I want to build a factory, but the kind of object returned depends on a value read from a bean that is somehow a cache. So of course, I can't call the bean's ...
Luis Sep's user avatar
  • 113
5 votes
2 answers
151 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
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
3 votes
3 answers
4k views

Implementing a thread-safe factory with caching

I have a ConnectorFactory that creates Connector objects based on parameters like URLs, username and passwords. The ...
Wernsey's user avatar
  • 133
4 votes
1 answer
10k 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 ...
MiamiBeach's user avatar
6 votes
1 answer
224 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,381
3 votes
1 answer
127 views

Factory Class for Game World

The world in my strategy game is comprised of a number of towers. At the start of the game, only one tower is generated, and when the player discovers new towers they are created and added to the ...
bazola's user avatar
  • 8,579
4 votes
1 answer
452 views

Properly using parameterized Factory.Create() method using DI

My factory is using method injection because I thought this was the best way to make it so far. Besides, I doubt it is a good thing after having to call on its ...
Will Marcouiller's user avatar
4 votes
1 answer
78 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: ...
jth41's user avatar
  • 253
6 votes
1 answer
104 views

Is this a fair use for a factory pattern?

...
user46957's user avatar
8 votes
2 answers
2k views

Factory Method implementation

Can you please verify my approach? ...
Thava's user avatar
  • 83
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
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
4 votes
1 answer
105 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 ...
theateist's user avatar
  • 263
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
5 votes
1 answer
244 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
169 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
6 votes
2 answers
232 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
3 votes
1 answer
998 views

Extending prototype of given instance from factory method

I created a rubber ball by extending instance of b2Body prototype of Box2D.js. I get the instance from factory method b2World#CreateBody. ...
suzukimilanpaak's user avatar
1 vote
1 answer
2k views

using (IDisposable) in c# factory pattern

How will this example affect the using implementation in GetSite? ...
Eric Herlitz's user avatar
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 ...
3 votes
2 answers
250 views

RFC on "Factory" code [closed]

This is the first code of this type that I've attempted, so I'm wondering if anybody would be willing to critique it. It's "sort of" (I think) a factory class. I want to keep it as simple as possible (...
B. Clay Shannon-B. Crow Raven's user avatar
1 vote
1 answer
365 views

PHP design pattern factory input for products and quotes

I'm working on figuring out the best way to design this so that it's well organized and it seems like the factory design pattern makes sense. Updated: What I'm building: - Pricing calculator - ...
Steve's user avatar
  • 111
4 votes
1 answer
3k views

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

Consider this class: ...
Mathieu Guindon's user avatar