Skip to content

Instantly share code, notes, and snippets.

@GRAgmLauncher
Created April 15, 2015 08:12
Show Gist options
  • Save GRAgmLauncher/32c83b0458b78eff2c5f to your computer and use it in GitHub Desktop.
Save GRAgmLauncher/32c83b0458b78eff2c5f to your computer and use it in GitHub Desktop.
Tight coupling
interface FooContext {
public function foo(); // i.e. cache
public function bar(); // i.e. dbConnection
public function baz(); // i.e. logger
}
// If we're not doing dependency injection, then you need to handle permutations like below...
// It's easy to see how quickly this gets out of control
class StandardFooContext implements FooContext
{
public function foo()
{
return new FileCache(...);
}
public function bar()
{
return new PDOConnection(...);
}
public function baz()
{
return new Monolog(...);
}
}
class StandardFooContextWithMongoDB implements FooContext
{
public function foo()
{
return new FileCache(...);
}
public function bar()
{
return new MongoDB(...);
}
public function baz()
{
return new Monolog(...);
}
}
class StandardFooContextWithMongoDBAndRedisCache implements FooContext
{
public function foo()
{
return new Redis(...);
}
public function bar()
{
return new MongoDB(...);
}
public function baz()
{
return new Monolog(...);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment