Thinking in Model in Windows form development

Source: Internet
Author: User
ArticleDirectory
    • What's the problem to be addressed
    • The concepts in MVC
    • The two points as the solution

The model is the M in MVC which is the current popular design pattern in Asp.net.

To think in model, I have two points.

    1. Model depends on the interfaces.
    2. Divide the business logic on the model into independent units.
What's the problem to be addressed

Although we have web services to hold the core business logic, there are quite a lot of bueinss logic in the client end to be coded mixed with the UI elements. this leads to testing, which launches the whole system to input or click, and finally distracts the programmer from testing the business logic itself.

This problem is outstanding in the recent development for the availability of child type. But the bugs are reported both in holding UI area and the drilldown UI area.

In addition, it is known that the UI is more changable than the business logic in the UI. thus, we are commonly demanded by the end user to put the current existing UI element together or lead another UI style to implement the existing business logic. for example, the implementation in the wizard and Lookbook mode which are error-prone and poorly maintained.

As the scale of the system grows, the complexity of the system may exponentially increase that may be awful to the maintenance.

So we have to make changes to proceed with the complexity.

The concepts in MVC

The MVC design pattern is popular in Microsoft ASP. net. it grows from Asp.net MVC to Asp.net MVC 4, which demonstrates the design pattern's concepts are not only valid tive but also powful. the core concept in the MVC is to isolate the business logic from the influence in UI elements. so the programmer can concentrate on coding on the business logic and take unit test to guarantee its correctness directly instead of lauching the whole system to do the tedious inputting and clicking to test.

However, the MVC design pattern is implemented as a framework in Asp.net. So it is impossibile to introduce it into our windows form development environment.

The variation of MVC is MVP that has been implemented by smart client software factory (scsf) in microsfot platform. considering the impact of introduction of scsf to the current development, it wocould not be achieved in a short term.

So what we coshould do in short term is to introduce the concept into the development.

The two points as the solution

The tow points are involved in the model. the model shoshould encapsulate the business logic of domain and it dosn't have anything to do with the UI elements. so the model can be depended by the UI area safely to respond the business logic from the UI elements consistently. I will explain the two points in the model below.

Model depends on the interfaces
    1. The interface return the data requested in the model to implement the business logic
    2. The returned data from the interface can be mocked which is the important pre-condition for the unit test
    3. The parameters in the methods of the interface shoshould be as simple as possible to facilitate the mock Process
    4. The interface can be determined by the analysis on the domain of business logic. if the business logic is not involved the domain of business logic in the model, you can hide it behind the interface. another way to judge if the some business logic can be hidden by the interface is to see if the business logic can be unit tested in the model.
Divide the business logic on the model into independent units

Actually, the indpendent units are synonyms of public methods in the model. This approach takes the following advantanges.

    1. The aspects of the business logic on the model can be expressed clearly
    2. Each public method can be guarded by the series of unit tests to guarantee the correctness.

To make the method can be guarded by unit test, they shocould take return-type to check the correctness in the unit test.

 

The goal of the two points is to help the programmers concentrate on the coding business logic and testing the correctness. and then, the container of the business logic can be invoked everywhere without differences. eventually, the valuable point-the consistence of the business logic in multiple UI area is achieved. (The goal sounds very attractive)

 

I will appreciate if you cocould send any of your feedback on the article.

Or please go to our company novasoftware for more information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.