[Composite UI] [design mode] MVP or MVC?

Source: Internet
Author: User

**************************************** ****************************
*Copyright Notice
*
* This document uses the Creative Commons release. Please strictly abide by this authorization protocol.
* This article was first published onBlogThis statement is an integral part of this article.
* Author's network name: prodigal son
* Author EMAIL: Dayichen (at) 163.com
* Author's BLOG: Http: // Www. Cnblogs. Com/Walkingboy
*
**************************************** ****************************

 

 

[Composite UI] [design mode] MVP or MVC?

-Written by prodigal son @ cnblogs.com (06-12-20)

Abstract:

MVP or MVC? CAB has always been a typical application of MVP. Recently, we have considered MdiForm implementation in our Web MVP framework. Remember CAB. winForms has similar implementation of MdiWorksapce. I checked all the Hands On Labs examples of CAB yesterday and found that the examples do not adopt the MVP mode. I feel a bit "misuse ", by the way, I thought about how to use CAB to achieve true MVP. I will record it for the moment.

I. Re-emphasize: MVP and MVC

Unlike MVC, MVP does not rely on business logic controller but on abstract APIs of business logic.

Therefore, the key to distinguishing MVPs from MVC lies in whether the View depends on a specific business object.

Ii. MVC of CAB Labs

Taking the CAB Labs code as an example, the definitions and associations between different layers are as follows:

CustomerWorkItem: drives a complete Customer UseCase

CustomerDetailView: displays the UI of Customer Details

CustomerDetailController: encapsulate the Detail function of CustomerWorkItem and expose the service interface to CustomerDetailView.

How to Use mermerworkitem in CustomerDetailView

 
 
// We use our controller so we can show the comments page
[CreateNew]
Public CustomerDetailController Controller
{
Set {controller = value ;}
}

We can see that the View only depends on the OB injection function and obtains the Controller through object injection, but its injection type is the specific mermerdetailcontroller, rather than the abstract object (such as IControlller ), in this way, although the IoC function is used, the dependency still exists.

Of course, there are many examples of solutions for View coupling, such as the Publisher and Subscriber of EventBorker, and CommandHanlder. It seems that they can solve the specific View dependency problem because they all depend on abstract WorkItem, however, when the Controller is also integrated, the independence of the View is suddenly damaged.

3. MVC reconstruction of CAB Labs

In fact, the key to the dependency in Labs is the dependency on the specific Controller. If we can refactor this part so that it depends on an IController just like WorkItem, we can completely separate the View.

How to abstract IController is the key point.

The controllers of various services may be different, and some may even contradict each other. It is difficult to abstract their common points.

My previous framework is generic. For example, some View-related constraints are defined based on the View's pass characteristics:

 
Public interface IController
{
Void ViewLoad;
Object LoadData;
Bool UpdateData;
Void ViewClose;
//....
}

 

The Controller injects the View based on the configuration file, so as to solve the View's responsibilities (collect data and display data ).
However, in the actual coding process, we found that this method avoided the features of the business, so that during coding, we always felt that it was difficult to use it, and it was a bit itchy.
So how can we solve the ever-changing problem of business objects? In fact, the CAB has provided an excellent solution.
First, the IController interface constraint function is weakened. The interface is as follows:
 
 
 
 
Public interface IController
{
}
It is an empty API. What about business functions?
Don't forget the WorkItem implementation method ......
At this time, you will find that EventBroker & CommandHandler is so useful. The IView and IController are combined through configuration, and then the associated events and commands between them are automatically registered,
You will find that encoding is restored to the previous process-oriented method, but all components are loosely coupled.
Iv. MVP of CAB Labs
All the above mentioned are MVC, but CAB is used to remove the specific dependencies of the Controller. At this time, it is necessary to reconstruct the MVP.
You only need to transfer the control initiative to the Presenter (restructured by the Controller. The simplest conversion method is to directly remove the Controller object in the Labs example,
Using WorkItem as a Presenter object directly, all dependencies disappear. This is why I am confused about adding a Controller object to Labs, and I have not found its advantages.

The above ideas are purely subjective fantasies, and the Framework Code refactoring ing ......

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.