In this chapter, I’ll explain how interfaces identify functionality that can be tacked onto a type. I’ll then show you how a type can implement an interface to offer this well-defined functionality, allowing the type to be used in various scenarios easily. Finally, I’ll demonstrate useful techniques for avoiding problems when you use interfaces—namely, duplication of member names and compromised compiletime type safety.
When programming, it’s useful to think of an object as being of multiple types because the type of an object describes its capabilities and behavior. For example, you could design a
SortedList type that maintains a set of objects in a sorted order. You could add any