MVP is a derivation of the MVC pattern.
In MVP, view receives the events from the UI and calls the presenter as needed.Presenter is responsible for updating the model and view as needed.
- M - Model
- V - View
- P - Presenter
In MVP, view receives the events from the UI and calls the presenter as needed.Presenter is responsible for updating the model and view as needed.
MVP vs MVC
MVP | MVC |
---|---|
Model-View-Presenter | Model-View-Presenter |
Presenter is responsible for binding model and view | Controllers are based on behaviors and can be shared across views |
Usually view to presenter map one to one. Complex views may have multi presenters. | Can be responsible for determining which view to display |
The view is in charge. | The controller is in charge. |
References : http://stackoverflow.com/questions/2056/what-are-mvp-and-mvc-and-what-is-the-difference
There are two types in MVP.This image explains those perfectly.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MangoIC.Plugins; using MangoIC.controllers; namespace MangoIC.views { public partial class PurchasingView : Form, IPurchasingView { public PurchasingView() { InitializeComponent(); } public string Name { get { return this.name.Text; } set { this.name.Text = value; } } public string Model { get { return this.model.Text; } set { this.model.Text = value; } } public string Make { get { return this.make.Text; } set { this.make.Text = value; } } public string Color { get { return this.color.Text; } set { this.color.Text = value; } } public string Size { get { return this.size.Text; } set { this.size.Text = value; } } public string Price { get { return this.price.Text; } set { this.price.Text = value; } } public string SalesPrice { get { return this.salesPrice.Text; } set { this.salesPrice.Text = value; } } public PurchasingPresenter Presenter { private get; set; } private void saveBtn_Click(object sender, EventArgs e) { Presenter.savePurchase(); } } }Getters and Setters are used by the presenter to retrieve data from the UI and also to populate data in the UI.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using MangoIC.views; using MangoIC.models; using MangoIC.dao; namespace MangoIC.controllers { public class PurchasingPresenter: IPurchasingPresenter { private readonly PurchasingView _view; private readonly PerchasingDao _pdao; public PurchasingPresenter(PurchasingView view) { _view = view; view.Presenter = this; _pdao = new PerchasingDao(); } public void savePurchase() { Console.WriteLine("saving purchase.."); StockItem stockItem = new StockItem { Name = _view.Name, Model = _view.Model, Make = _view.Make, Color = _view.Color, Size = _view.Size, Price = _view.Price, SalesPrice = _view.SalesPrice }; _pdao.saveStock(stockItem); } } }
In here we are creating a Item using the details we retrieve from the view and save it the DB using a DAO layer inside the savePurchase() function.
Download the example (Visual Studio 2010) : Link
(You may have to download some of the dependencies when executing the program)
Query for the table creation;
CREATE TABLE `stocks1` (
`Id` int(11) NOT NULL,
`Name` varchar(45) DEFAULT NULL,
`Make` varchar(45) DEFAULT NULL,
`Color` varchar(45) DEFAULT NULL,
`Size` varchar(45) DEFAULT NULL,
`Price` varchar(45) DEFAULT NULL,
`Sales_Price` varchar(45) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Comment below, if you have any questions.
The best Iron Bridge Iron Bridge Iron Belt of 2021
ReplyDeleteIron Bridge Iron Bridge Iron Belt of 2021. grade 23 titanium Iron Bridge Iron Belt trex titanium headphones Of 2021 Iron Bridge Iron Belt Of 2021. Iron Bridge Iron stainless steel vs titanium apple watch Belt Of 2021. Iron Bridge trekz titanium pairing Iron Belt Of microtouch titanium trim
site dildo,dildos,vibrators,sex toys,male sex doll,custom sex doll,real dolls,dog dildo,wholesale sex toys my response
ReplyDeletet744t0wajxt006 sex dolls,wholesale sex dolls,realistic dildos,couples sexy toys,double dildos,sex chair,cheap sex toys,dildos,dildos i416n9locsn160
ReplyDelete