From the course: Object-Oriented Programming with C#

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Interfaces

Interfaces

- [Instructor] Up until this point we've been hard coding all of our types to classes but one of the advantages of object-oriented programming is that we can use something called interfaces to decouple our code. An interface is a contract between two classes that define all of the public properties and methods that can be used. Earlier I talked about how the player and the room are both going to need to act as inventories. We can't have those classes extend inventory so instead we're going to add all the properties and methods of the inventory through composition, similar to what we did with the inventory class, and how we added logic on top of the builtin.net list class. Let's look at how this'll work. First, we need to create an interface, so we can do this by refactoring our existing inventory class and pulling out all the public properties and methods. Let's go back to our inventory class and right click on the…

Contents