6. Software Design Model
The Software Design Patterns describe the problems of the policies followed by the application software design principles. In other words, a software design principle is a good idea, and a software design pattern is a tool you use to implement such a good idea.
The idea of the Software Design pattern first came from the book Design Patterns: Elements of Reusable Object-Oriented Software. This book inspired the creation of many other books describing software design patterns.
For example, another book, The Head First Design Pattern, introduced GOF's book Design Patterns in a more understandable way: design Patterns introduced in Elements of Reusable Object-Oriented Software. This book details a total of 14 software design patterns:
◆ Strategy
◆ Observer
◆ Decorator
◆ Factory
◆ Singleton
◆ Command
◆ Adaptor
◆ Fa C ade
◆ Template
◆ Iterator
◆ Composite
◆ State
◆ Proxy
◆ Compound
Another book that has a greater impact on software design Patterns is Martin Fowler's Patterns of Enterprise Application Architecture. This book also has a company website, which lists the models described in this book. The website is http://www.martinfowler.com/eaacatalog /.
The Software Design Pattern allows you to build your code in a pattern to make it more adaptable to future flexible modifications. For example, when building the forum application in this article, we use a software design pattern named Repository for design. Eric Evans describes the Repository mode in his book Domain-Driven Design:
A repository describes all objects of a certain type as a conceptual set (typically simulated ). Its behavior is similar to a set, but it has more detailed support for queries. Therefore, objects of the corresponding type can be added or deleted, while the systems behind the REPOSITORY can add or delete them from the database.
According to Evans, a major advantage of the Repository model is that it can help you implement "application and Domain Design and storage technology, multiple database policies, it is even a decoupling between multiple data sources." In other words, the Repository mode prevents your applications from being changed due to different database access methods.
To make our forum applications stand out from a specific storage technology, we will introduce the above Repository mode in the system. Therefore, the final design of this forum application will allow us to switch between different data access technologies such as LINQ to SQL, Entity Framework, or nhib.pdf.
7. Test-driven development
I plan to use the test-driven development principles to build the MVC forum application in this article. More specifically, before I write any application code, I will first write a unit test for the application code.
Test-driven development will bring you higher quality code for the following reasons:
(1) Writing and testing your code provides you with a security net suitable for future changes.
(2) writing tests for your code forces you to write loosely coupled code.
(3) writing a test for your code before writing your code will force you to observe your own code from a user's perspective.
Let us analyze the advantages of each of the above features in a more detailed manner.
First, unit testing provides you with a security net that can adapt to future changes. This is a point that Michael Feathers has repeatedly stressed in his book "Working extends tively with Legacy Code. In fact, he defined the legacy code as "Simple coding without testing ".
When your application code is overwritten by unit testing, you can modify the code without worrying that the change will implement the existing functions of your code. Unit testing helps to make your code more secure for refactoring. If you can refactor your code, you can use the software design pattern to modify your code, which will produce Code better adapted to future changes.
Second, compliance with test-driven development will force you to write code in a specific way. Tested Code tends to lead to loosely coupled code. Unit tests can be performed in Isolated Code units. To build your application so that it can be tested, you need to build the application using an isolated component method.
A class is loosely coupled with another class, which means you do not have to change another class when you change the first class. Test-driven development often forces you to write loosely coupled code, because loosely coupled code can withstand changes.
Finally, writing code in the test-first mode forces you to observe your own code from the perspective of a user. By writing code in the test mode, you will be able to work from the developer's perspective that may use your code in the future. Since writing a test forces you to consider how another developer (maybe yourself in the future) uses your code, the code you finally write should be better designed.
8. The immediate interests of motu should be based on the long-term
Using the test-driven development principle to build software requires developers to make more efforts at the beginning of software development. Although it takes some time to write a test, the idea is that the effort required to initially build a unit test will be rewarded in the future.
There are two ways to make you a developer. You can grow into a cowboy or a craftsman. A cowboy can start encoding immediately. That is to say, a cowboy can build a software application quickly. However, as a cowboy, the problem is that the software must be maintained for a long time.
A craftsman is very patient. A craftsman will always develop a software carefully. A craftsman always builds unit tests very carefully and makes them cover all the code in an application. Therefore, it takes a longer time for a craftsman to successfully create an application. However, this application is easy to maintain after it is created-it is easier to modify errors and add new features to the application.
9. Summary
In short, our ultimate goal is to build an MVC forum application that can withstand long-term testing. It should not only work well now, but also continue to work in the future-even when someone needs to make changes to the application.
I want to use the Microsoft ASP. NET MVC framework to develop this forum application. The reason is that this framework makes it easier for me to write test code for a program. On the other hand, the ASP. net mvc framework itself provides the most loyal support for test-driven development from the beginning of design.
- Introduction to ASP. net mvc Framework
- Introduction to MvcAjaxPanel in ASP. NET MVC
- ASP. net mvc Framework to save UpdatePanel
- Use ASP. net mvc source code to find a solution
- ActionInvoker of ASP. net mvc Framework