Linked Questions

17 votes
2 answers

Factory Pattern and/or Dependency Injection? [duplicate]

I understand the concept and can use both the Factory Pattern and Dependency Injection, however they seem a little at odds with each other conceptually. Is it a case of using one over the other? Or ...
Samuel Hawksby-Robinson's user avatar
2 votes
5 answers

Are there too many parameters in this constructor? [duplicate]

Check this out: public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Registry $registry, ...
user1806244's user avatar
-3 votes
1 answer

Should you use your own implementation of inversion of control instead of a dependency injection container? [duplicate]

I have a small project that has 6 service classes and a main class. Since they are service classes and does not store any state in it, I declared one static method in each one: class Main calls A....
Alperen Üretmen's user avatar
20 votes
5 answers

What are the benefits of dependency injection in cases where almost everyone needs access to a common data structure?

There are plenty of reasons why globals are evil in OOP. If the number or size of the objects needing sharing is too large to be efficiently passed around in function parameters, usually everyone ...
vsz's user avatar
  • 1,496
23 votes
5 answers

Are "factory methods" anti-pattern now?

I consider Joshua Bloch's Effective Java the best book on the language that I read. However, I started to wonder about something One of the things he suggested was to prefer public static factory ...
demavi's user avatar
  • 347
17 votes
4 answers

Techniques for minimising number of function arguments

In Clean Code, it is written that "the ideal number of arguments for a function is zero". The reasons why are explained and make sense. What I'm after is techniques to refactor methods with 4 or more ...
Neil Barnwell's user avatar
13 votes
4 answers

This way I'm writing this code is testable, but is there something wrong with it I'm missing?

I have an interface called IContext. For the purposes of this it doesn't really matter what's it does except the following: T GetService<T>(); What this method does is look at the current DI ...
LiverpoolsNumber9's user avatar
4 votes
4 answers

Is it bad to use DI to inject constructor parameters at runtime?

These are two classes, the first one I inject an instance of type IEngine while the second one I inject owner's name, tickets and engine. Version 1: public class Car { public Car(IEngine ...
Anonymous's user avatar
  • 2,049
8 votes
5 answers

When to use DI and when to create yourself in Java

I've a decent amount of OOP with various languages but am pretty new to Java. I'm reading through a lot of tutorials where large numbers of objects are created within the code of a class, and I'm ...
GordonM's user avatar
  • 6,435
5 votes
3 answers

How to initialize all your references?

I have recently taken a project with another developer, and he has a certain way of initializing his references. class Player { private: Console &console; Armor &armor1, &...
Bugster's user avatar
  • 4,023
2 votes
3 answers

Abstract Factory with Pure DI

I have an application where I'm using pure DI to construct my object graph. I would like to use a factory so I can create and destroy instances of a certain class at run time. The trouble is that ...
Rob L's user avatar
  • 106
1 vote
1 answer

How should I construct a complex object having many dependencies?

Consider the construction of the FixAcceptor type below. The code snippet is part of a unit test. var logSource = LogSource.OnMessage | LogSource.Event; var stateStore = new StateStore(); var ...
Matthias Güntert's user avatar
3 votes
1 answer

Composite repositories: minimizing dependency injections

I have an application with dependency injection that consumes a REST API. The API calls are abstracted into entity-specific repositories. Some of the repositories are: HttpNotebookRepository, ...
Amal K's user avatar
  • 101
2 votes
0 answers

How to decouple a message broker and its message handlers?

Project description: I have a nodejs project where I try to build a bluetooth mesh like network, each node consists roughly of 4 parts the frontend part, the message broker, a bluetooth client and a ...
MADforFUNandHappy's user avatar
0 votes
1 answer

Dependencies traveling through hierarchical viewmodels

Often I want to open a new window from within some view. I see opening a window as view logic. So I don't want code in my viewmodel that creates/opens/changes Windows or anything else that interacts ...
user2190492's user avatar