Browse Articles. Shailendra Chauhan Print 3 min read 21 Jul Net Framework to develop the web application. This framework implements the MVC pattern which helps to provide separation of code and also provides better support for test-driven development TDD.
Net MVC is a lightweight and highly testable open source framework for building highly scalable and well-designed web applications. Here is the list of the released version history of ASP.
Net 3. Net 4. Net Asp. Net Identity ASP. Net MVC Framework. It first executes when the user sends a request. Then the action determeines which view will be shown. It connects to both the View and the Model. It can send commands to its associated view to change the view's presentation and can also send a command to change the model's state. It processes in the way that it reads data from the view controls user input and sends input data to the model. A controller can be associated with multiple views, in other words we can define multiple actions in a controller and depending on the action, an associated view is shown.
It is the principal part of the MVC architecture. It is similar to the Business Layer of 3-tier architecture. Model A Model is associated with Views and a Controller. It produces the updated output on the view.
Often the model objects retrieve data from the database and stores data to the database. It handles the logic for the application's data domain. View Views are the components that display the application's User Interface UI , in other words it manages the displays of information.
Often the views are created from the model data. In a loosely coupled application, you can make a change to one component of an application without making changes to other parts.
Over the years, several principles have emerged for writing good software. These principles enable you to reduce the dependencies between different parts of an application. Robert Martin did not invent all the principles; however, he was the first one to gather the principles into a single list. Here is his list of software design principles:.
For example, according to the Single Responsibility Principle, a class should have one, and only one, reason to change. There are other lists of software design principles. For example, the Head First Design Patterns book has a nice list. You should also visit the C2. Software design patterns represent strategies for applying software design principles. In other words, a software design principle is a good idea and a software design pattern is the tool that you use to implement the good idea.
The idea behind software design patterns was originally promoted by the book Design Patterns: Elements of Reusable Object-Oriented Software. This book is known as the Gang of Four book. This book has inspired many other books that describe software design patterns. The Head First Design Pattern book provides a more user-friendly introduction to the design patterns from the Gang of Four book.
This book has a companion website that lists the patterns from the book: www. Software design patterns provide you with patterns for making your code more resilient to change. For example, in many places in this book, we take advantage of a software design pattern named the Repository pattern. It acts like a collection, except with more elaborate querying capability.
For example, when we write our blog application at the end of this book, we take advantage of the Repository pattern to isolate our blog application from a particular persistence technology. By taking advantage of software design principles and patterns, you can build software that is more resilient to change. Software design patterns are architectural patterns. They focus on the gross architecture of your application.
If you want to make your applications more change proof on a more granular level, then you can build unit tests for your application. A unit test enables you to verify whether a particular method in your application works as you intend it to work. First, unit tests provide you with a safety net for change. When your application code is covered by unit tests, you can modify the code without the fear that the modifications will break the functionality of your code. Unit tests make your code safe to refactor.
If you can refactor, then you can modify your code using software design patterns and thus produce better code that is more resilient to change. Refactoring is the process of modifying code without changing the functionality of the code. Second, writing unit tests for your code forces you to write code in a particular way. Testable code tends to be loosely coupled code. A unit test performs a test on a unit of code in isolation. To build your application so that it is testable, you need to build the application in such a way that it has isolatable components.
One class is loosely coupled to a second class when you can change the first class without changing the second class. Test-driven development often forces you to write loosely coupled code.
Loosely coupled code is resistant to change. When writing a unit test, you take on the same perspective as a developer who will use your code in the future. Because writing tests forces you to think about how a developer perhaps, your future self will use your code, the code tends to be better designed. In the previous section, we discussed the importance of building unit tests for your code.
Test-driven development is a software design methodology that makes unit tests central to the process of writing software applications. When you practice test-driven development, you write tests first and then write code against the tests.
First, you write the unit test. The unit test should express your intention for how you expect your code to behave. When you first create the unit test, the unit test should fail. The test should fail because you have not yet written any application code that satisfies the test. Next, you write just enough code for the unit test to pass. The goal is to write the code in the laziest, sloppiest, and fastest possible way.
You should not waste time thinking about the architecture of your application. Instead, you should focus on writing the minimal amount of code necessary to satisfy the intention expressed by the unit test. Finally, after you write enough code, you can step back and consider the overall architecture of your application.
In this step, you rewrite refactor your code by taking advantage of software design patterns-such as the Repository pattern-so that your code is more maintainable. You can fearlessly rewrite your code in this step because your code is covered by unit tests. There are many benefits that result from practicing test-driven development. First, test-driven development forces you to focus on code that actually needs to be written.
Because you are constantly focused on just writing enough code to pass a particular test, you are prevented from wandering into the weeds and writing massive amounts of code that you will never use.
In other words, when practicing test-driven development, you constant write your tests from a user perspective. Therefore, test-driven development can result in cleaner and more understandable APIs. Finally, test-driven development forces you to write unit tests as part of the normal process of writing an application.
As a project deadline approaches, testing is typically the first thing that goes out the window. When practicing test-driven development, on the other hand, you are more likely to be virtuous about writing unit tests because test-driven development makes unit tests central to the process of building an application.
Building software designed for change requires more upfront effort. Implementing software design principles and patterns takes thought and effort.
Writing tests takes time. However, the idea is that the initial effort required to build software the right way will pay huge dividends in the future. There are two ways to be a developer. You can be a cowboy or you can be a craftsman. A cowboy jumps right in and starts coding. A cowboy can build a software application quickly. The problem with being a cowboy is that software must be maintained over time. A craftsman is patient. A craftsman builds software carefully by hand. A craftsman is careful to build unit tests that cover all the code in an application.
It takes longer for a craftsman to create an application. However, after the application is created, it is easier to fix bugs in the application and add new features to the application. Most software developers start their programming careers as cowboys.
At some point, however, you must hang up your saddle and start building software that can stand the test of time. The Microsoft ASP. The ASP. NET MVC framework was designed from the ground up to make it easier to build good software in the sense of good software discussed in this chapter.
In other words, the framework was designed to make it easier to implement software design principles and patterns when building web applications. Furthermore, the ASP. Web applications written with the ASP.
Because ASP. NET framework. NET framework consists of a vast set of classes, tens of thousands of classes, which you can use when building any type of software application. For example, the. NET framework includes classes for working with the file system, accessing a database, using regular expressions, and generating images. NET framework is one part of the. It contains a set of classes that were created specifically to support building web applications. For example, the ASP.
NET framework includes classes for implementing web page caching, authentication, and authorization. Microsoft has two frameworks for building web applications built on top of the ASP. NET Web Forms. Some developers find the style of programming represented by ASP.
0コメント