Published Sep 3, 2013

I is for Interface

    Delve into the world of programming interfaces with Joe Zack and Michael Outlaw as they explore the fundamentals and advanced uses, comparing interfaces to abstract classes, and unravel the intricacies of effective implementation and the Interface Segregation Principle to enhance code flexibility and maintainability.
    Episode Highlights
    Coding Blocks logo

    Popular Clips

    Episode Highlights

    • Interface Basics

      Interfaces are fundamental in object-oriented programming, serving as a contract that classes must adhere to. Michael Outlaw explains that interfaces define how you should interact with a piece of data or memory at runtime, without giving full access to the underlying structure 1. Joe Zack likens interfaces to guardrails on a highway, guiding how a class should be used in a given context 1. This analogy highlights the flexibility and control interfaces provide, allowing different implementations based on the context, much like how one might behave differently in various social settings 1.

      Joe has a method called speak. His interface is now speak. And, and there's, there's different implementations of that. There's Joe speaks to grandma. So when you implement that class, that's obviously going to be removing a lot of choice language and whatever else might be there. Whereas when Joe speaks at the club Friday night, you know, it's a different ballgame.

      --- Alan Underwood

      Alan Underwood further elaborates that interfaces describe a "can do" relationship, emphasizing their role in defining capabilities without dictating how they should be executed 1.

         

      Abstract vs. Interface

      The discussion then shifts to the differences between interfaces and abstract classes. Michael Outlaw points out that abstract classes allow for some implementation, requiring users to build upon them with specific use cases 2. In contrast, interfaces are purely declarative, with no storage or implementation details assigned 2. Alan Underwood notes that while both abstract classes and interfaces must be inherited or implemented, interfaces offer a cleaner approach by avoiding the complexities of multiple inheritance 2.

      Another key point that they both do share in common is an abstract class has to be inherited, whereas an interface must be implemented.

      --- Alan Underwood

      Joe Zack adds that this distinction is crucial in languages like C# and Java, which support single inheritance, thus making interfaces a vital tool for defining multiple behaviors without the pitfalls of multiple inheritance 2.

    Related Episodes