Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [factory]

In object-oriented programming (OOP), a factory is an object for creating other objects.

0
votes
2answers
78 views

Object composition in a static function

I have a class that provides basic functionality of a modal window. For different situations I need to provide different modals(different number of buttons, titles, etc...). I have a kind of factory ...
0
votes
1answer
72 views

Factory Design Pattern Implementation with multiple interfaces and base class

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
-2
votes
4answers
174 views

Static Factory Methods vs Constructors

Which one of the following way is recommended and why? Date d = Date.from(curr); Date d = new Date(curr); Can you also provide some examples behind the reasoning?
0
votes
1answer
48 views

Pseudo-Factory Abstract Class

So I have a requirement for something like this: The client shouldn't be aware of how the actual classes are implemented or constructed. The classes implement a common interface So I used Factory ...
2
votes
2answers
135 views

Does it make sense to implement a Class Factory design in an RPG Character Creation module

I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning ...
2
votes
2answers
139 views

Passing DI container to a factory – is this always an antipattern?

Generally I would always answer "yes" to this question, because at this point, your DI container has become a service locator, and you're losing the benefits of DI. However, I wonder if it is ...
0
votes
1answer
258 views

DDD - Factory or Service?

I'm new to DDD, and I'm confused at the very start of my DDD project. To setup a context, I'm building the user management part of my app, so I'm building my Account entity, which contains an Id, a ...
0
votes
1answer
67 views

Factory pattern with creators

The software should be able to: Draw shapes on a drawing Save drawings Load drawings Adding a new shape should have a limited effect on existing code. There is no user cases, no clues about ...
2
votes
1answer
52 views

MVP Passive View -> Dependency Injection -> Factory Pattern -> Is testing behaviour whilst ignoring state enough?

I am writing an application using the Model/View/Presenter passive view pattern. I have view that contains multiple items in a list. My model is of type AudioDrama. For filtering that list I have ...
1
vote
3answers
178 views

Is the Factory pattern good for this situation?

Im developping for my company a software where clients can requests app deployements and upgrades. Each request has 3 status (Validated, Started and closed). For every type of request (deployment ...
1
vote
2answers
66 views

Factories and event binding

Factories are used to create objects. I was wondering if it's against the purpose of a factory, if I would bind couple of objects together in the factory. Let me illustrate this with an example. Let'...
5
votes
1answer
202 views

Approach for Constructing View Models in Complex MVVM Application

I'm struggling with the design in a WPF MVVM application. In a few courses I've taken, they say that having a lot of parameters in a constructor is a code smell, but they never address how to deal ...
3
votes
4answers
423 views

Is Abstracting your code too much a bad use of SOLID Principles?

After an unresolved argument with a friend I decided to ask the stack overflow community. Is there something like abstracting your code too much? Which of the following is the better option. We come ...
0
votes
4answers
137 views

Should a class which has a method to create object A also implement a method to delete A?

For example, suppose I have a class to create a button with specific styles common to my app: class ButtonFactory{ public: static Button* createAppButton(std::string st,int font size){ Button* ...
1
vote
1answer
219 views

Domain driven design - factory with cross-cutting concerns

I was recently tasked with creating a factory that processes webhook events. Any authorized application in the solution (1 app per domain) can post any meaningful payload and as long as the event's ...
1
vote
2answers
123 views

Does only a create method classify a class as a factory?

In my current project, I find my self making factories, but for two very distinct reasons: Reason #1: To assist my IoC container if a particular class needs an parameter that is only known when the ...
1
vote
0answers
111 views

Are constructors with complex initialization logic always bad? [duplicate]

I've recently read this blog post regarding what a constructor should do and I am also reading Eric Evans' book on Domain Driven Design. Both the blog post and the book state that a constructor ...
0
votes
0answers
119 views

Unit of Work, Factory and Lifetime Management

Yesterday, an argument arose in the office, on the usage of a unit of work versus a DbFactory producing these. To give a bit of a context, we have a (loosely) service-oriented architecture, following ...
2
votes
0answers
58 views

Best design pattern/approach for a Factory which needs multiple types of input

I want to develop a Factory of INotifications. public interface INotification { string Text { get; } string UserId { get; } NotificationType NotificationType { get; } } The problem is, ...
2
votes
2answers
141 views

With the Static Factory Constructor design pattern is there a preferred way to remove “all” object references?

Consider the following implementation of a static factory pattern... public class Names{ private static final Map<String, Name> NAME_MAP = new HashMap<>(); private final String firstName, ...
1
vote
2answers
179 views

Picking a concrete type based on a configuration parameter

I have a code base that contains several different instances of the following pattern, the key point of which is that the concrete type of the class is decided at run time based on a string from a ...
2
votes
1answer
243 views

How do I create front end test data based on backend model's schema?

I'm really struggling with creating robust tests for my frontend because of the coupling in data schema between my backend and frontend. To clarify, I have a Django rest API and I have a front end ...
1
vote
2answers
179 views

What is the proper (or preferred way) to configure a static factory class?

First SE stack, I am working on a large chunk of old Java code and am finding tons of duplication and inconsistently configured/created objects because of different authors, skill levels, etc. I ...
3
votes
1answer
216 views

What is the generic implementation of design pattern IoC coupled with Factory for DAO? [closed]

I'm learning the java Spring framework. So far, I understood that Spring will make stuff transparent with its configurations so that IoC and Factory are not too complicated to implement... Now I have ...
3
votes
3answers
199 views

Constructor for factory expecting instance used only in products

I have a factory that creates products. To do this I need an instance of some other class, that has nothing to do with the actual factory. However all Products should of course use the same instance ...
0
votes
2answers
160 views

How to handle Factory-like structures with a huge amount of classes?

I have the issue that I want to be able to capture a set of SNMP messages, and some of them I want to parse to create an instance of a user-defined class. I may for example want to identify whether an ...
1
vote
2answers
1k views

Should a factory always create a new object

we have a hierarchical structure where every node is derived from a node base class public Node(INodeFactory nodeFactory). The factory is injected so the node can create its child nodes using Get(int ...
0
votes
2answers
266 views

Add method to interface for only one implementation

I have a factory for an interface with different implementations. But one implementation needs an extra method which the others don't need. How do I solve this without implementing "not implemented ...
1
vote
2answers
284 views

How to combine these fill and create methods or utilize generics in factory?

Domain object "Contragent" Let's say I have an hierarchy of classes: public class BaseContragent { public int Id { get; set; } } public class PersonContragent : BaseContragent { public string ...
3
votes
1answer
123 views

Can I create a Factory method which holds an internal reference to an instance of B?

Given two classes: class A { B* b_; A(B* b){ b_ = b; } } class B {} B is a class that should be used only inside A so I would like not to expose its creation to whatever class ...
1
vote
2answers
56 views

Class member declared only to be passed to other class

Given three classes: class A { B* b_; A(B* b){ b_ = b; } void doThings() { C* c = new C(b_); ... // Use c } } class B {} class C { B* b_; ...
0
votes
2answers
97 views

Creational Pattern for creating or returning an object from other objects

A problem I've come across and never really had a good answer for, is: what is the correct design pattern for creating or returning an object from another object, or multiple objects? Traditionally I'...
1
vote
3answers
3k views

Static Method in Interface

I'm working on software to play back log files. We have different types of logs from different providers. I've created an interface that different classes will implement to play different logs. For ...
3
votes
1answer
5k views

Is mixing Builders and Factory pattern a good idea?

I have an object Carconstructed using builder pattern. Issue was a lot of code redundancy. Car.Builder builder = new Car.Builder("Mercedes"); builder.numDoors(carConfig.getNumDoors() ...
1
vote
2answers
164 views

Aim of Factory pattern is to stop us from over-riding or re-writing the functions which instantiate?

http://www.cs.unc.edu/~stotts/GOF/hires/pat3cfso.htm CreateMaze is the function which instantiates the objects. IMO, according to factory pattern we are not supposed to overload or modify or re-write ...
7
votes
3answers
202 views

Are we “allowed” to use methods on JavaScript maps (the data type) and if so are there any new rules?

JavaScript maps (the data type, not the array method) seem set up to accept data (key/value pairs) but not necessarily methods. At least they're not advertised that way. However, we can put methods ...
4
votes
1answer
113 views

What alternatives are there to using an object of a contravariant interface polymorphously?

The gist of what I'm trying to do is get an instance of the appropriate user service, then pass it whatever subtype of User we're working with. Models: public class User { public string ...
7
votes
2answers
253 views

Gateway Pattern and Composition

I often write database intensive applications and discovered the gateway pattern which seemed to fit my needs. My problem now is that many of my models are compositioned of other models. For example ...
8
votes
3answers
568 views

DI/IoC container vs factories: Where do I configure my application and why?

I am trying to figure out when to use the DIC/IoC registry for configuring my software and when to use factories, along with the reasoning behind either approach. I am using StructureMap as my DI ...
0
votes
1answer
507 views

How can you have a Repository with dynamic data-sources?

Usually the Repository pattern looks like : What would be the best practice to make the repository handle more gateways (for Cache Redis, FTS/filtering Elasticsearch, Db Mysql etc.) My ideas so far ...
2
votes
1answer
171 views

Working with Dependency Injection using Factory pattern

I want to build a .jar that encapsulates a vendor api, so we can use our own objects as parameters to communicate with the api. I've read some articles and topics here in SO, but I still am a bit ...
0
votes
1answer
43 views

Factory injection into factory created object

public class Factory { public INode CreateNode(TypeEnum type) { switch(type) { case TypeEnum.Document: return new DocumentNode(this); case ...
2
votes
1answer
109 views

How to keep IDs in sync when using Factory?

abstract class Product { public abstract Product createProduct(); ... } class OneProduct extends Product { ... static { ProductFactory.instance().registerProduct("ID1", new OneProduct(...
3
votes
4answers
3k views

Are factories that only return one type of object bad?

Someone in a Stackoverflow post (I didn't bookmark the question unfortunately) commented, that Factories that only return one type of object are a code smell. I find myself writing these kinds of ...
2
votes
2answers
634 views

Can a single Factory be used to create similar in purpose, but different in focus objects?

I am concerned about whether or not I am using FactoryMethod correctly. Background: I am refactoring legacy code and I have identified a pattern: there is a God Object that is created in memory,...
1
vote
3answers
147 views

SOLID principles and generating many objects from a file

The "D" in SOLID stands for dependency inversion. If I have for example, a Blacksmith class that depends on Hammer, I should create my Hammer externally and pass it to Blacksmith, rather than having ...
1
vote
1answer
450 views

What is the DRY-est factory pattern to instantiate subtypes based on one of their properties' values?

Take the following class hierarchy: Client FacebookClient PinterestClient TwitterClient Each client must define a value for an enum property named ClientType (string property Url in the original ...
3
votes
1answer
1k views

Project structure: Where to put object factories

I am working on a C# programming project in Visual Studio. I have created various VS library projects inside the VS solution containing the various components of the solution. Without giving it too ...
2
votes
3answers
844 views

Pattern to use (if any) to co-ordinate loosely coupled classes with strong interdependencies

I have a collection of cooperative classes whose behaviors are interdependent upon one another. But I wish to keep them loosely coupled, so I've created appropriate interfaces. I want to determine an ...
1
vote
1answer
92 views

Rewriting conditionals in OOP without generics

Let's say I have a set of objects, foo f; bar br; baz bz; I also have a string of JSON data, string JSONstring; Depending on the object type of the JSON string, I need to transform it into ...