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
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 ...
3
votes
3answers
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 ...
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 ...
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 ...
1
vote
0answers
1k views

AngularJS factory, return object to be used again in factory

I'm trying to create a wrapper / factory around the cordova media plugin, which requires you to create a new Media object, and then use it again to pause, stop, play, etc it. The factory + link to ...
3
votes
1answer
118 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 ...
4
votes
1answer
277 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 ...
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: ...
6
votes
1answer
101 views

Is this a fair use for a factory pattern?

...
7
votes
2answers
1k views

Factory Method implementation

Can you please verify my approach? ...
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: ...
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
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 ...
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 ...
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 ...
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 ...
3
votes
1answer
964 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. ...
1
vote
1answer
1k views

using (IDisposable) in c# factory pattern

How will this example affect the using implementation in GetSite? ...
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 ...
3
votes
2answers
248 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 (...
1
vote
1answer
276 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 - ...
4
votes
1answer
3k views

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

Consider this class: ...
5
votes
2answers
1k views

Is this a correct way to use Factory Pattern?

I have an abstract class which implements the IDataCreator interface: ...
9
votes
2answers
3k views

Is this a good implementation of the Factory Pattern?

Suppose I have this code: ...
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 ...
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 ...