zoukankan      html  css  js  c++  java
  • 显示接口和隐式接口的区别:

    一、新建一个接口类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// InterF 的摘要说明
    /// </summary>
    public class InterF
    {
        public interface hide
        {
            string show();
        }
        public interface display
        {
            string show();
        }
    
    }
    

    二、新建接口实现类,hide.cs和display.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// Speaker 的摘要说明
    /// </summary>
    
    public class hide : InterF.hide
    {
        public string show()
        {
            return "隐示接口";
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// Speaker1 的摘要说明
    /// </summary>
    public class display : InterF.display
    {
        string InterF.display.show()
        {
            return "显示接口";
        }
    }
    

    三、新建一个default.aspx文件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InterF.hide c = new hide();
            c.show();
            hide s = new hide();
            s.show();
            Label1.Text = s.show() + c.show();
    
    
            InterF.display c1 = new display();
            c1.show();
            Label2.Text = c1.show();
            //下面写法将引起编译错误错误“PetShop.Speaker”不包含“Speak”的定义
            //display s1 = new display();
            //s1.Speak();
        }
    }
    

    四、综上总结:显示接口和隐式接口的区别

     <1>隐示实现接口和类都可以访问 显示实现只有接口可以访问。

    <2>显示实现益处

    1:隐藏代码的实现功能

    2:在使用接口访问的系统中,调用者只能通过接口调用而不是底层的类来访问,有利于安全性

     综上:当类或结构继承接口时,意味着该类或结构为该接口定义的所有成员提供实现。接口本身不提供类或结构能够以继承基类功能的方式继承的任何功能。基类实现接口,派生类将继承该实现

  • 相关阅读:
    项目经理-要材料
    java stream 处理
    listGiftBagShowInfo 这个方法 我搞了一晚上
    BigDecimal.ROUND_UP 如果 从 double 到 Decimal 有异常, 必须从double到String然后 Decimal 就可以了
    json串 转 list<class> 方法 List转JSONArray和JSONArray转List
    昨晚加班到3点多-身体都虚脱了
    MVN 点击compile总是失败
    IDEA使用笔记(八)——自动生成 serialVersionUID 的设置
    Maven 版本号规范
    java多线程学习
  • 原文地址:https://www.cnblogs.com/May-day/p/5389091.html
Copyright © 2011-2022 走看看