views:

93

answers:

2

I was reviewing 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?

+5  A: 

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.

Justin Niessner
I think thats a good explaination. Basically, you can be sure that things are separate. Its helpful for keeping a constant seperation of code, but useful for binding code together also so you aren't duplicating. But then when it comes to people reusing your interfaces, they know how to implement it so that everything is talking the same language.
Laykes
+2  A: 

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.

tvanfosson