i know loosely coupled and tightly coupled information. But i suspend when can i decide where and what time use? i dont understand when i need loosely coupled and tightly coupled ?
look please : http://www.dofactory.com/Patterns/PatternAdapter.aspx#_self1
if you look adapter class :
///
/// The 'Adapter' class
///
class Adapter : Target
{
private Adaptee _adaptee = new Adaptee();
public override void Request()
{
// Possibly do some other work
// and then call SpecificRequest
_adaptee.SpecificRequest();
}
}
Above usage like tightly coupled! i think that tightly coupled is bad usage. But adapter pattern used tightly coupled. When i need tightly and loosely coupled?
Remember that Gang Of Four patterns were born before Dependency Injection which is mentioned a lot as loose coupling.
So, the example Adapter pattern you show is to trying to show how pattern works and does not care much loose coupling.
If you want your code testable and replaceable, loose coupling should be used, example:
To inject
customerRepositoryvia constructor, it makes easy for you to mockICustomerRepositoryin order to do Unit Test.