I have just seen an answer here on SO (What is the difference between loose coupling and tight coupling in the object oriented paradigm?), where the following code was shown to demonstrate tight coupling:
class CustomerRepository
{
private readonly Database database;
public CustomerRepository(Database database)
{
this.database = database;
}
public void Add(string CustomerName)
{
database.AddRow("Customer", CustomerName);
}
}
class Database {
public void AddRow(string Table, string Value) { }
}
But is that really true? I would say this is an example of constructor injection and therefore not tight coupling at all. Even the article on Wikipedia about DI lists this case, so I do not get why that answer is so upvoted.