[ELI5] Why use an interface?

I'm new to c# and having stumbled upon interfaces it just baffles me.

why would you use it?

take this for example:

public interface IPizza { public void Order(); } public class PepperoniPizza : IPizza { public void Order() { //Order Pepperoni pizza } } public class HawaiiPizza : IPizza { public void Order() { //Order HawaiiPizza } } 

why would you need that interface?

what's the difference of just implementing Order in both PepperoniPizza, and HawaiiPizza like this

public class PepperoniPizza : IPizza { public void Order() { //Order Pepperoni pizza } } public class HawaiiPizza : IPizza { public void Order() { //Order HawaiiPizza } 

by HalcyonAbraham via /r/csharp

Leave a Reply