I is for Interface

Topics covered
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
Design Patterns Part 3
Answers 383 questions

Clean Code - How to Write Classes the Right Way
Answers 383 questionsDesign Patterns Part 1
Answers 383 questionsASP.NET 5 - It's Basically Java
Answers 383 questionsHow to be an Intermediate Programmer
Answers 383 questionsHow to be a Programmer
Answers 383 questionsNDepends on How Good Your Code Is
Answers 383 questionsClean Code - How to Write Amazing Functions
Answers 383 questionsWhat is Supple Design?
Answers 383 questions95. Data Structures – Arrays and Array-ish
Answers 383 questions

Software Design Anti-patterns
Answers 383 questionsDesigning Data-Intensive Applications – Scalability
Answers 383 questions

Algorithms You Should Know
Answers 383 questions
Clean Architecture - Fight for Architecture
Answers 383 questionsThere is still cool stuff on the internet
Answers 383 questions
