Thinking in Model in Windows Form development

來源:互聯網
上載者:User
文章目錄
  • 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 cope 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 effective 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 would not be achieved in a short term.

So what we could 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 should 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 should 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 should 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 could send any of your feedback on the article.

Or please go to our company novasoftware for more information.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.