Created
January 20, 2014 17:03
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public sealed class HappyController : Controller { | |
| private IManagement management; | |
| public HappyController(IManagement management) { | |
| this.management = management | |
| } | |
| [HttpGet] | |
| public ViewResult LooselyCoupleThings() { | |
| return View(this.management.GetSomething()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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