 Hey everybody this is Brian and welcome to the 38th lamp tutorial. Today we're going to be discussing interfaces. So let's just start by cranking out some cold here. Did I say cold or cold? It's been a long day. So interface and let's say person. And actually that's bad form. We should say I person. Now typically you would name an interface starting with an I. That way you know it's an interface. And then we'll just say public function say name. Now what is this? We haven't really seen this before. We got an interface. Got a name. Looks a lot like an abstract class because it's got a function that's not defined. There's no code block. And it's very similar. But the difference between an interface and an abstract class is an interface is not a class. An interface is a contract between objects. And I'm going to explain that here real quick. Let's actually make another interface. We'll call it I employee. Public function say ID because every employee has an ID number. And we're going to actually extend the I person interface. Now this looks an awful lot like a class. In fact it is inheritance. It uses extends. So we're extending the I person interface. So you can create multiple interfaces and can join them into one bigger interface. See we have an I person and then the I employee. Now let's actually make a class. Class manager implements. We'll say I employee. Now you see how we're not extending the I employee. We're implementing the interface. What does that mean? Well these don't exist in memory. And I'm not going to bore you with a long lengthy lecture on how memory works. But you should know that unlike a class these actually don't exist in memory. They're just a blueprint in its most basic sense of the word. It's just a structure. It's an abstract abstract class as you would call it but it's an interface. So an interface is just a contract saying that this object will have these functions. So the manager class we should implement these functions. Now how do you go about implementing them? Well pretty simple actually you just saved it. Let's grab this and then we'll grab this. Now notice how no errors being thrown. We actually can run this without everything it needs. So let's say we made a boo boo. That's the official technical term for it by the way is a boo boo. Notice how it has say name but it doesn't have say ID. Let's actually try and run this and see what happens here. Notice how hmm didn't spit it out. Why? Because there's an error. When you make an interface you have to define everything that you implement. I should say you have to implement everything you've defined. See how we're implementing I employee and we're only defining say name or we're only implementing say name. We also need the say ID. Now suddenly magically it works. Why? Because in the background it's throwing a fatal error. And if you've watched my tutorials on the error handling it's a little bit different when it gets into object-oriented programming but it's there. You can just simply test that by doing that. So an interface is a contract saying that the manager class implements or agrees to implement everything in the I employee interface. The I employee interface has the say ID but it also extends the I person interface through inheritance. So it also must implement the say name function. And there you have it. Now you may be asking yourself why in the world do you need any of this stuff? I remember when I first learned this I'm not going to say how long ago it was because it was a very, very, very, very long time ago. But when I learned all this stuff I remember sitting there going why do you need this? You can just make the functions in your class. You don't need any of this template interface guck. Well actually you do. Think about it this way. If you're writing code for a company, how many different types of employees are in that company? Well you've got, let's see, you've got your male boys or your male girls depending. You've got your HR people. You've got your sales people. You've got your IT folks. Even in IT you've got database people. You've got programmers. You've got web designers. You've got graphic designers. You've got business intelligence on and on and on. Well each one of those has the same basic functions. Each one of them should have an employee ID or a name. So you use an interface to define a minimum level or a contractual obligation that if it's going to be this type of person, a manager, a sales person, a HR drone, they're going to need to implement that interface. That way you can target that interface. You need to know that every type of class, whether it's a manager or a mail clerk, they're going to have the minimum allowed or I should say the minimum required, which would be in this case, name and ID. It takes a while to wrap your new head around that. Trust me, it took me a little while. But once you actually get into interfaces and really into object-oriented programming, they're a real life saver, especially if you start working in a team environment. Because let's say you're working on this massive code base that's going to target different types of employees and you're working on the manager class but someone else is working on, say, the HR class. Well, that's when you need an interface, a standard agreed upon way of doing things. So that's all for this tutorial. I hope you found it educational and entertaining and thank you for watching.