Why are there so many Interfaces in an MVC application
I was revie开发者_JAVA技巧wing the code for KIGG and noticed that there are so many Interfaces. I am fairly new to MVC and do understand what an interface is, a bit.
How does Interface work in MVC, why is it used?
The same reason you would implement interfaces for other applications...to abstract the implementation away from the usage.
It allows the ASP.NET MVC Framework to use your code even though the Microsoft Developers didn't have your implementation before they wrote the Framework.
Also, like tvanfosson mentions...the use of Interfaces also greatly enhances the ability of the ASP.NET MVC team to properly Unit Test their Framework.
I think the major reason why you may see more interfaces in an MVC application is the new emphasis on testability. That is one of the significant changes with MVC, testability is given more weight in the design of the framework. Interfaces are much easier to work with in designing unit tests because they allow you to develop mock implementations for your tests to use. Over time I would expect much of .NET (like the Web.Abstractions) to move to more testable (abstract bases classes/interfaces) forms.
精彩评论