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
0
votes
1answer
46 views

Use of Factory pattern — how to implement it

I am trying to figure out how Factory pattern works. I implemented it with TypeScript in this github repo: https://github.com/emilecollin/factory_pattern Basically this is emulating spaceships gaming ...
1
vote
0answers
94 views

Animal class with Threads and factory

it's my first time working with threads and I had this Homework to solve: Homework Text: Program a class called Animal. Animals have a spatial position that represented by an x ​​and a y coordinate (...
3
votes
1answer
162 views

Grouping low-level services together into a high-level service

I am working on an e-commerce website. What I need to do is to save an advertisement. The ad has some properties and some photos... properties should be save to DB and photos should be saved to file ...
4
votes
1answer
98 views

Java enum-based factory to calculate entry parameters

I want to create a factory to return all Source instances that match given entry parameters- that is, I want to iterate through some Collection of objects and for each entry check boolean method. I ...
5
votes
0answers
116 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 ...
1
vote
1answer
63 views

Creating a ModelBinder to Sanitize user input in HTML format

I have a custom model binder which takes user input in HTML format, sanitize the HTML input by removing any script or XSS threat and returns the sanitized HTML string: ...
1
vote
1answer
40 views

Create a pump object from either one of pump model number or pump product id

Consider this code: ...
5
votes
3answers
1k 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 ...
0
votes
1answer
87 views

Factory to instantiate and configure Selenium WebDriver

I, also, need to know whether this is a valid implementation of the factory pattern. The amount of effort which goes into configuring DriverFactory to simply get a ...
3
votes
1answer
105 views

Instantiating View Models using a static factory

I am building an e-commerce website. I have an application layer service called SearchService. SearchService receives a search ...
0
votes
2answers
175 views

Factory method to create two kinds of cars based on an enum

I am implementing the factory method approach. My intention is to know if my approach is correct for factory method. Any modifications to be done to align with the approach? First I am creating an ...
4
votes
1answer
606 views

Electricity billing system for home in OOP

I recently appeared for interview for code-pairing round and I was asked following question: Electricity Billing System for home. The corresponding power usage of home appliances (Fan, AC, Fridge, ...
2
votes
1answer
45 views

PHP Factory Pattern : Should I use `create()` or `__invoke()`?

I currently had a colleague reviewing my code and he had a comment on a factory class I created. It's very simple: ...
1
vote
2answers
213 views

Synchronizer for importing XML files into a database when folder content changes

I have created a Synchronizer, the purpose of which is to read data from an XML source file and store the result in a DB. I have different source types, for example Student.XML, School.XML, etc. ...
1
vote
2answers
1k views

Shape area calculation

I know questions with this text has been asked and already answered, but my question is mainly limited to only one method of this flow and where it should be. I have an assembly for Shape's area ...
4
votes
0answers
73 views

Chained Factories by Expression Template

I want to make factories that can chained together to create a pile of layers. One of the advantage of chained factories is that later factories can pass specifications to earlier factories. For ...
1
vote
0answers
23 views

Logs UI errors to a service provided in the configuration

As part of the project I am currently working on we want to log our UI component errors as well. I developed this package as a base. It's a factory (basically, not sure if it's correctly a factory). ...
2
votes
1answer
119 views

Factory Design Pattern in Java [closed]

I am currently attempting to understand the fundamentals of factory methods in Java and I found a lot of exampels where a pattern like this has been used. I got some exercises about sorting algorithms ...
8
votes
4answers
729 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 ...
2
votes
0answers
250 views

Show mobile SoundCloud player in WebView

Demo for a SoundCloud player in WebView for specific song or artist stream as a workaround because SoundCloud is not accepting API key request anymore. SoundCloudWebView: ...
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 ...
1
vote
2answers
70 views

JavaScript library to notify watchers of changes

Background Last year, while I was still entering the beginning of Immutability and Pure functions and whatnot I created a library for the community called ...
5
votes
2answers
169 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 ...
7
votes
1answer
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 ...
1
vote
3answers
77 views

Choose betwen a few message values depending on 3 variables

This code write out the title and the body of a message depending basically on 3 variables combination. How could i refactor this nicely? a factory pattern? how more precisely? a mapping array ? but ...
2
votes
2answers
5k views

Using Autofac to do DI in a static factory method

I'm using Autofac to create one of my classes inside of a static factory method Create. This code is working and I haven't noticed any side effects yet. Admittedly, ...
1
vote
0answers
33 views

Factory method to make JSON requests for various types of list items

I have the following code: ...
1
vote
1answer
528 views

utility class for reading in JSON

I'm reasonably happy with the execution: ...
2
votes
1answer
299 views

Rendering SharePoint lists into tables with any number of columns

I have the following code, but first the explanation. I am using a REACTJS Office UI Component called details list: https://developer.microsoft.com/en-us/fabric#/components/detailslist And I want my ...
1
vote
2answers
201 views

Two similar factory classes to instantiate services

I'm working on building a library to help you bootstrap the development of a Java API. The premise is, you can have your controllers implement interfaces like ...
1
vote
0answers
56 views

Creating objects by defined name

I'm trying to write universal factory creating objects by name. I've got some working prototype now but there must be a better way than casting construction methods to void pointer. ...
0
votes
1answer
3k views

A factory with static objects or an enum with instance objects?

My application accepts different messages. A message is described by its schema. enum ...
0
votes
2answers
89 views

Class-based Message System Pattern

I'm trying to create an extensible system for building messages. I want each style of message to be a unique class. I don't want the client to have to worry about the class type when creating the ...
1
vote
2answers
882 views

Correct implementation of the factory pattern in php

All, during my vacation I am trying to learn myself the basic principles of OOP and the factory pattern in php. I read a lot of tutorials and websites (e.g. http://www.phptherightway.com) and began to ...
7
votes
4answers
5k 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 ...
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 ...
2
votes
1answer
454 views

DDD Domain Objects, Factories, and Presenters

Aloha, I am working to understand some of the different pieces of domain driven design. In this particular case, I have a NameFactory that builds a Name domain object. I also have a NamePresenter ...
0
votes
2answers
135 views

PDO anonymous function inside a Factory

In this question here on S.O, the accepted answer suggests to use both anonymous function and factory pattern for dealing with PDO connection. I believe the anonymous function is used in case a ...
2
votes
0answers
596 views

Simple files parsing and info extraction

First let me describe the problem, we want to solve: We have hierarchical directories structure with different types of templates. Each type of templates is located in dedicated folder. Hierarchical ...
1
vote
2answers
331 views

Factory design pattern with Shapes

I'm making the very common example of Factory design pattern which creates a factory of shapes and return an instance of the type Shape. I wonder which is the best way to replace that bunch of nested ...
1
vote
1answer
111 views

“Factory” which produces a “connection” object

I am a newbie in C# and in OOP in general. I decided to create a class that should give out a "connection" object. I would like your advice and critique on improving it. ...
2
votes
1answer
195 views

Factory design pattern for circles and polygons

I am going over a number of design patterns and today I ask you to please inspect my application attempt of the Factory design pattern. Please feel free to share what you think about it, because my ...
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 ...
3
votes
1answer
475 views

Generating Settings Objects from Database via Factory Class

In an ASP.NET MVC application (C#) have a factory-like class that generates settings objects of ISettingType for my application. However, some settings are very ...
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
2answers
175 views

Factory for report handlers

Below is my try. ...
1
vote
1answer
265 views

Factory to create Finite Impulse Response filters in C++

I've recently begun a project in digital signal processing and am using C++ as the programming language. In this project, I have implemented several finite impulse response (FIR) filters. Many of ...
3
votes
2answers
3k views

Window Factory and Manager using MVVM pattern

I am fairly new to Factories and Dependency Injection in MVVM. I've build my View(Window) factory with help from SO, and I would like to know if I had implemented everything properly(code works just ...
6
votes
2answers
963 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: <...
3
votes
2answers
109 views

Sequence generators not only for potatoes but also for apples and oranges

The last question about sequence generators Growing potatoes in delayed sequences was only about potatoes. I thougt why not make it work with apples and oranges too so I made it generic. The base ...