Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created January 20, 2014 17:03
Show Gist options
  • Select an option

  • Save DominicFinn/8524072 to your computer and use it in GitHub Desktop.

Select an option

Save DominicFinn/8524072 to your computer and use it in GitHub Desktop.
The sad controller is tightly coupled to a specific implementation of the management class. We need to be coding against interfaces. This grants us at least two major wins: 1. We can refactor / improve the management class without worrying about the controller, we just need to ensure the interface is still satisfied. 2. We can test different par…
public sealed class HappyController : Controller {
private IManagement management;
public HappyController(IManagement management) {
this.management = management
}
[HttpGet]
public ViewResult LooselyCoupleThings() {
return View(this.management.GetSomething());
}
}
public class SadController : Controller {
[HttpGet]
public ViewResult TightlyCoupleThings() {
IEnumerable<string> something;
using(var management = new Management()) {
something = man.GetSomething();
}
return View(something);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment