接口减少程序耦合度

多个类或组件要用到同样的功能,只需实现接口功能

被调用类不需要知道调用类具体是哪个类,只需要调用类实现接口的

将处理的代码封装在实现接口的类中,每个类有不同的处理。

1.接口

public interface ISearch
{
      void setSearch(string id, string name);
}

 

2.录入窗体

public partial class AddEntVideo : Form, ISearch
{

        public AddEntVideo()
        {
            InitializeComponent();
        }

        {
            SearchEnterprise searchEnterprise=new SearchEnterprise(this);
            searchEnterprise.ShowDialog();
        }

private void btnSearchEnt_Click(object sender, EventArgs e)   

  {     

       SearchEnterprise searchEnterprise=new SearchEnterprise(this);      

       searchEnterprise.ShowDialog();     

  }

      //高内聚 ,将处理的代码封装在实现接口的类中,每个类有不同的处理

       public void setSearch(string id, string name)

        {
            lblEnterpriseID.Text = id;
            txtEnterprise_Name.Text = name;
        }

2010061112054256.jpg

3.查询窗体

 

 public partial class SearchEnterprise : Form

    {

        private ISearch iSearch;

        public SearchEnterprise(ISearch iSearch)

        {

            InitializeComponent();

            this.iSearch = iSearch;

        }

 

        public SearchEnterprise()

        {

            InitializeComponent();

        }

 

  private void dgvEnt_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            if(e.RowIndex!=-1&&e.ColumnIndex==0)
            {
       iSearch.setSearch(this.dgvEnt.Rows[e.RowIndex].Cells[0].Value.ToString(), this.dgvEnt.Rows[e.RowIndex].Cells[1].Value.ToString());

            }
            this.Close();
        }

2010061112104247.jpg

转载于:https://www.cnblogs.com/zw123456/archive/2010/06/11/1756269.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值