When we assist developers with new applications using the .NET framework, there is always a question of what is the best architecture for development? In most cases, we recommend the model-view-controller software architecture. The MVC architecture isolates the domain logic from the user interface, allowing for faster, more controlled development. MVC is under continued enhancements, providing more benefits with each new version.
Model-view-controller has three layers: the model, the view, and the controller. The model can be considered the data used in the program, the controller includes the class files with the business logic, and the view is simply the user interface. By isolating the model, the view, and the controller, development is faster, complexity is easier to manage, and there is more control over the behavior of the application.
- Managed Complexity – The separated nature of model-view-controller makes it easier to manage the complexity of large applications and keep it well organized. Developers are able to focus on one aspect of implementation at a time, such as concentrating on the view without depending on the business logic. Some functions and classes of MVC can even be auto-created to save time.
- Faster Test-Driven Development – With MVC, it’s easier to test applications than it is to test Forms-based ASP.NET web applications. This is because the separation of application tasks are all defined differently so they add no more complexity. Developers can test very short development cycles by writing a failing automated test case to define a desired improvement or function, then writing the new code.
- Rapid, Parallel Development – Because of the loose coupling of the MVC architecture, it’s easier for more than one developer can code at the same time on the application. If one developer is working on the view, another on the controller logic, and the last on the business logic in the model, the application can potentially be completed three times faster. Using other architectures, the three developers are more likely to step on each other’s toes. But with model-view-controller, they code independently and simultaneously.
- Full Control Over Behavior – The MVC framework is ideal for developers who want full control over the behavior of their application because MVC does not use a view state or server-based forms.
- Code Reuse – Since the controller uses different pieces of the model and view to create a request, many of these parts can be reused in other MVC applications. These reusable building blocks are chosen by the controller to handle specific processing (model) and display (view) requirements.
- No Viewstate or Postback Events – Rather than using Viewstate or Postback events to store the state of server controls on the page and to manage invocation of server side events, MVC instead uses different view engines to generate the markup that streams back to the browser client. The advantage here is that you can produce more standard markup and have greater control over what will be rendered to the client.