In the previous article on the abstract class, the actual interface and the use of abstract classes there is no big difference they can only be inherited. But the use of the environment is not the same. Abstract classes use functions that compare a set of things. But the interface is biased toward something that does not understand the intersection of functions. Let's take a look at how it's used, and the code looks like this:
Define a USB interface Interface iusb { void usb (); } //define a NIC interface interface Networkcard { void networkcard (); } //defines a computer that has these interface features public class computer1 : IUSB, Networkcard { public void usb () { messagebox.show ("This is a usb1.0 interface"); } public void networkcard () { MessageBox.Show ("This is a NIC interface"); } } public class computer2 : iusb, networkcard { public void usb () { messagebox.show ("This is a USB2.0 interface"); } public void networkcard () { MessageBox.Show ("This is a NIC interface"); } } private void button1_click (object sender, eventargs e) { Computer1 cmp = new compUter (); cmp.usb (); cmp.networkcard (); //can do the same / / iusb iusb = cmp; Iusb.usb (); }
I believe that people from the code, more than the text narrative easier to understand it. This is the function of the interface.
Use of the C # interface