Realization and principle of interface mapping

Source: Internet
Author: User

Looking at Allen Lee, base class and interface mixed inheritance declaration issues, a personal view.

Run the following code first:

namespace Test
{
using System;
  
Interface interface
{
void method ();


Class base class: interface
{
public void method ()
{
Console.WriteLine ("This is the base class method Oh!");
}

Void interface. Method ()
{
Console.WriteLine ("I am an interface-specific implementation Oh, don't run away. ");
}
}

class has no inheritance for interfaces: base class
{
/**////<summary>
///Here only new methods can be used to overwrite
///</summary>
Public New void Method ()
{
Console.WriteLine ("I can only block it with new, however, in idesign Programming specification, new is not recommended. ");
}
}

Class has interface inheritance: base class, interface
{
void interface. Method ()
{
Console.WriteLine ("This Called a remapping of interfaces, it's just a trick thing. ");     
}
}

class TestClass
{
[STAThread]
static void Main (string[] args)
{
Base class C1 = new base class ();
C1. method ();       

Interface I1 = new base class ();
I1. Method ();

Console.WriteLine ();
     
 Inheritance C2 = new Without interface () No inheritance of interfaces ();
C2. Method ();       

Interface i2 = new has no interface inheritance ();
I2. Method ();

Console.WriteLine ();

There is an inherited C3 = New Interface Inheritance ();
C3. Method ();       The

Interface i3 = new has interface inheritance ();
I3. Method ();     

Console.read ();
}
}

Let's look at the hierarchy of the code's class diagram first.

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.