<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AspxMVP.aspx.cs" Inherits="WebApplication1.AspxMVP" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbl" runat="server"></asp:Label>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
<asp:Button ID="bt" runat="server" Text="Enter" OnClick="btn_Click" />
</div>
</form>
</body>
</html>
namespace WebApplication1
{
//这里只引用界面和IAspxMVCPresenter,其它的都不引用,特别是业务逻辑层。Entity可以
public partial class AspxMVP : System.Web.UI.Page, IAspxMVPView
{
IAspxMVCPresenter presenter;
public AspxMVP()
{
presenter = new AspxMVCPresenter(this);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Display();
}
}
protected void Page_Init(object sender, EventArgs e)
{
//presenter = new AspxMVCPresenter(this);
}
public string Text
{
get { return txt.Text; }
}
public string Lable
{
set { lbl.Text = value; }
}
protected void btn_Click(object sender, EventArgs e)
{
presenter.Save();
}
private void Display()
{
var list = presenter.GetList();
//绑定操作;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebApplication1
{
public interface IAspxMVPView
{
//获取model数据后设置显示
string Lable { set; }
//获取界面数据后提交
string Text { get; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebApplication1
{
//视图依赖接口,而不依赖具体,可以不要此接口。
public interface IAspxMVCPresenter
{
void Save();
List<object> GetList();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1
{
//这里只引用IAspxMVPView和大量的model,特别是model的方法
public class AspxMVCPresenter : IAspxMVCPresenter
{
IAspxMVPView view;
public AspxMVCPresenter(IAspxMVPView view)
{
this.view = view;
}
public void Save()
{
var s = view.Text;
//可以持久化,调用model,获取model的数据进行显示。
view.Lable = string.Concat("您好:" + view.Text);
}
public List<object> GetList()
{
return new List<object>();
}
}
}
模式是为了解决依赖
面向接口编程,是为了不依赖具体实现。
设计模式能使不稳定依赖于相对稳定、具体依赖于相对抽象,避免会引起麻烦的紧耦合,以增强软件设计面对并适应变化的能力。
模式是一种代码的组织方式,跟算法或具体的解决方法不同。
算法主要是用来解决计算上的问题,而非设计上的问题。
数据结构是组织数据的一种方式。‘
软件架构是模块的一种组织方式。面向服务的体系架构,三层,插件,cs,bs,单层。构件。
设计模式是设计或代码的一种组织方式。23种
ASP.NET MVP模式主要作用是:
让页面集中处理页面相关的功能,不处理与model的交互,与model的交互由表现层处理。