I is for Interface

Topics covered
Popular Clips
Episode Highlights
Challenges
Interfaces present unique challenges and limitations in programming, as highlighted by Joe Zack and Michael Outlaw. Joe discusses the difficulty of associating interfaces with anonymous objects in C#, which requires creating real classes to return data, as interfaces can't be directly attached to these objects 1. He also mentions the inability to attach interfaces to existing assemblies, which complicates the use of built-in classes with custom methods 2. Additionally, Joe notes the restriction of not being able to define constructor methods in interfaces, which limits how classes can be created 3.
You can't define constructor methods in an interface, so I can't create an interface that informs the classes that implement me how those classes can be created.
--- Joe Zack
These challenges often require developers to find workarounds, such as using private classes or adapters.
  Â
Explicit Methods
Explicit method implementations in interfaces can lead to complex scenarios, as explained by Michael Outlaw. He describes situations where explicit interface methods are necessary, such as when two interfaces have overlapping method signatures 4. This requires developers to explicitly declare which interface method is being implemented, often leading to private methods that derived classes cannot access 5.
If you have to use it, do an explicit method implementation or interface implementation, but under normal circumstances you should just try to avoid it.
--- Michael Outlaw
Michael advises caution, suggesting that explicit implementations should be avoided unless absolutely necessary, as they can complicate code maintenance and readability.
  Â
Segregation Principle
The Interface Segregation Principle (ISP) emphasizes creating minimal interfaces, a concept Joe Zack finds crucial for effective team collaboration. He advocates for structuring code to lead developers into a "pit of success," ensuring they use the code as intended without unnecessary dependencies 6. By providing only the necessary methods through interfaces, developers can focus on essential tasks without being overwhelmed by irrelevant options.
No client should be forced to depend on methods it does not use.
--- Joe Zack
This principle helps maintain clean and efficient code, especially in large teams where communication and understanding are vital.
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
