Questions tagged [factory-pattern]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
6
votes
3answers
943 views

Should I use the Factory Pattern when instantiating objects with very different constructors?

Let's say (just for the sake of example) I have three classes that implement IShape. One is a Square with a constructor of Square(int length). Second is a Triangle with a constructor of Triangle(int ...
0
votes
3answers
557 views

Can Aggregate Root Factory create the root, and it's internal classes?

Currently, my aggregates and value objects have protected constructors and some of them are being created by static factory methods inside the aggregate with descriptive names. It creates a nice DSL ...
1
vote
2answers
127 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
1answer
96 views

Separation of concerns in object creation with factory and model

Thinking about the overall architecture of the application logic: Current status: The model contains all resources that are used at runtime. In a factory you register a builder which is used to ...
5
votes
1answer
212 views

Is this contract on an API user is inevitable?

I am designing a UI framework in Java. Every UI component, represented by the class Component, in the framework is identified by a non null unchangeable String key. So I get the key in the constructor ...
1
vote
1answer
187 views

Implementing a factory design pattern for GA selection

I've been working on different genetic algorithm selection methods recently. At the moment I have a RawFitnessSelction class, a RouletteWheelSelection class and a TournamentSelection class. I've been ...
-1
votes
4answers
1k views

Can factory pattern avoid code smell?

With two existing implementations, UFOEnemyShip & RocketEnemyShip, To introduce every new implementation implementing EnemyShip interface, shown below, changes are needed in factory class ...
0
votes
1answer
74 views

What does the details of instantiation encapsulation mean in factory design pattern?

I am trying to understand the factory design pattern and how it can be implemented in Javascript. So far what I understood is factory design pattern helps to create an instance of more specific class ...
1
vote
2answers
207 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 ...
0
votes
2answers
146 views

How to Avoid Missed Behaviors when Separating Code from Data

I've come across something that I find decently frustrating while adding new functionality to our large existing code base. Preface We have a variety of classes (ItemA, ItemB, ItemC...) that ...