1
vote
2answers
196 views

when using dependency injection, should I always pass an interface

When using depending injection, you generally pass everything around as an interface (perhaps with the exception of primitives and strings). That allows you to easily chance the behavior, without ...
4
votes
1answer
124 views

Reducing dependency cycles and reducing coupling

I'm trying to learn how to produce quality object-oriented code and have been studying concepts like SOLID. I'm currently working on an entity-component-process system for a small game engine. ...
4
votes
5answers
387 views

Questioning one of the arguments for dependency injection: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source): To construct an object, you first build its dependencies. But to build each dependency, ...
5
votes
1answer
332 views

Decoupling when constructors have non-contractual parameters

By non-contractual parameters, I mean parameters that are not interfaces or service dependencies, something like class Person(string name). I am writing a webpage scraping application, and so far ...
1
vote
1answer
95 views

How to properly handle conditional dependencies in a factory?

Let's say you have a string $action run-time, that specifies which type of $object needs to be created: $dbobject, $memcacheobject, $fileobject, $xmlobject, etc. Assume also, that creation of an ...
1
vote
2answers
151 views

Initialization of objects in a system using dependency injection

This is a follow up question to the following post: Injecting dependencies (DI) in c++ applications In a system that uses DI, someone, somewhere should be responsible to create the various objects ...
2
votes
2answers
209 views

Injecting dependencies (DI) in c++ applications

I am playing with dependency injection, but i am not sure I am doing it right. Especially, I am not sure what should be the correct way to build classes with injected dependencies. Say I have a class ...
1
vote
3answers
169 views

Should I consider loosely-coupling for class methods as well? [duplicate]

I'm a fan of Dependency Injection, however I don't know how much both public and private methods inside a class should be loosely-coupled. Just to picture it better, when I have both projectId and ...
2
votes
2answers
470 views

Factory Pattern and/or Dependency Injection?

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

Inject specific classes or not

I have a TableSqlBuilder interface which has a method getCreateTableSql. This interface is used in some other class as follows: function createTable( $tableDefinition ) { $sql = ...
1
vote
1answer
190 views

Unused dependencies and constructor injection

I have a class that has 3 dependencies. WritabbleDBConnection, ReadOnlyDBConnection and a QueryFilter utility object. I want to do constructor Injection so my class would look something like this. ...
9
votes
4answers
1k views

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
6
votes
5answers
366 views

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 ...
2
votes
2answers
616 views

How to program object-oriented with a DI framework? [duplicate]

Possible Duplicate: Does “Inversion of Control” promote “Anemic Domain Model”? My impression is that projects using a DI framework like Spring or Guice tend to lose their object orientation ...
4
votes
4answers
342 views

Are injectable classes allowed to have constructor parameters in DI?

Given the following code: class ClientClass{ public function print(){ //some code to calculate $inputString $parser= new Parser($inputString); $result= ...
2
votes
2answers
363 views

Is there a better way to design these classes?

I have two business classes: TimesheetDay and TimeSlot. One TimesheetDay can have one or more TimeSlots. The TimesheetDay and TimeSlot classes will be dependent on an object that implements a ...
8
votes
3answers
956 views

Keeping an MVC model loosely coupled from the DB?

I like to keep my code testable and have decided to go with the Dependency-Injection strategy for my current MVC framework, which definitely has proven to be a great way to ensure loosely coupled ...
3
votes
1answer
82 views

Test interface implementation

I have a interface in our code base that I would like to be able to mock out for unit testing. I am writing a test implementation to allow the individual tests to be able to override the specific ...