 Hey everybody, this is Brian. Welcome to the 16th C sharp tutorial. Today we're going to be discussing interfaces. I understand interfaces sound kind of big and spooky but trust me, they're pretty easy. So let's just say add class and we're going to make a new class and we're just going to leave it as class 1. And now we want to add a new item and choose interface. Now on the interface, let's just leave it as interface 1, just the default for now. And let's just say void do stuff. Oops and let's move this down here. Now you notice how that looks like a function but we're not actually implementing it. We don't have the brackets in here. Well the reason why is because an interface is simply a contract. It's saying if you're going to implement this interface you will have the things inside of it. Do stuff and then we will just say and you can have multiple things in here. We'll say do stuff again. And these are just function names and let's add a new item. Let's add another interface. Leave it as interface 2. We'll say void do more stuff and you can add pretty much as many things as you want in here. Now remember an interface is not a class. An interface is different in the fact that you don't actually implement anything. You just create an outline of what you want it to do. Saying if you're going to have interface 1 it will have do stuff and do stuff again. What does this mean? Well you know here's our class 1 and you know about inheritance. Well if you want to implement interface you would say interface. You notice how there's interface 1 and 2. Interface 1 and you can right click and implement interface and then implement interface explicitly. Now if you implement interface it just says add these items. So let's delete these. Right click again and do it explicitly. And it says interface 1.do stuff. Now the difference between those two is a little obscure. But really all you need to understand at this point is that an interface is a contract and there are multiple ways of having that contract. Because if your class has interface 1 it is in effect interface 1. I know that sounds confusing but really at this point just implement the interface so it's a part of your class. Now one thing you can do with interfaces you cannot do with inheritance is you can have multiple interfaces. Just put a comma and then say interface 2. And then right click and implement interface. See there's do more stuff that's from interface 2. Now you see these throw not implemented exemptions. Throw means it's going to create an error and then it's going to create a not implemented exemption class. So it really just means if you try to call that you haven't implemented it it's going to crash your program. It does that to get your attention. So that is one way you would get around the multiple inheritance block that C-sharp does not have. You use interfaces or contracts. Now if we go to run this let's actually say class 1. See class equal new class 1. And you see how we have all these properties or all these functions in here. Let's actually try to call one of these. I just want to show you what this exemption here does. And wait for it. Dramatic explosion there we go. Throw new not implemented. It says this method or operation is not implemented. So it's just their way of saying hey you got to fill this in. So let's click that little stop button. Now what happens. Let's just get rid of that so we don't crash a program again. If you don't implement an interface fully like let's get rid of do stuff and do stuff again. So we're missing out everything in interface one even though we said we're going to have interface. We've agreed to this contract. What do you think is going to happen when you go to run this program? We're just creating an instance of this class. Well it says there were build errors. And it says do stuff again not implemented. Do stuff not implemented. So that is what an interface does. It says if you're going to implement an interface you are agreeing. You are promising beyond a shadow of a doubt you will implement that interface. This would be very good for say a plug-in a system. Let's say you want to make any sort of application that has plug-ins. For example Firefox web browser has plug-ins. It has an interface you have to follow that guarantees that every plug-in is going to have functions that can be called. They'll get too caught up in the semantics of interfaces. At this point I just want you to understand that interfaces exist and that you can use them because we will use them in real world programming. And interfaces also allow you to implement multiple interfaces so you can get around the multiple inheritance problem. The problem with that though is that you have to create the code every single time. Because an interface you cannot implement it you can only declare it. That's a mouthful. Well this is Brian. Thank you for watching. I hope you found that educational and entertaining.