Перейти к содержимому

Interfaces vs Abstract Classes in Java: Mixins, Defaults and Skeletal Classes | Effective Java L21

The Modern SDE

0:00 / 0:00

Interfaces vs Abstract Classes in Java: Mixins, Defaults and Skeletal Classes | Effective Java L21

2 просмотра · 13 часов назад
The Modern SDE
1,25 тыс. подписчиков
2 просмотра · 13 часов назад
Lecture 21 of the Effective Java Masterclass by Engineer X · Part 3: Classes and Interfaces. In this lecture • Why a default toString in an interface is a compile error, and what that says about abstract classes • Single inheritance: an abstract class takes a class's only parent, an interface fits anywhere • Mixins and retrofitting: Refundable and Schedulable on payment classes that already have a parent • Three abilities need three interfaces or eight abstract classes (the 2^n explosion) • Default methods: when to write them, @implSpec, and their limits (no Object methods, no state, no protected members) • Skeletal implementations (AbstractFareRule, AbstractList): primitives, defaults, the Template Method pattern • Simulated multiple inheritance by forwarding, and simple implementations like AbstractMap.SimpleEntry • Modern Java: private interface methods (9), records implementing interfaces, sequenced collections (21), Map.entry • Interview: when you'd still choose an abstract class now that interfaces have default methods Chapters 0:00 A default that won't compile 0:54 One parent per class 2:01 Mixins: abilities as types 3:54 Three abilities, eight classes 4:47 Default methods and their limits 5:36 Skeletal implementations 7:56 Modern Java: records and sequenced collections 9:17 In the interview 10:04 Recap 10:31 Quiz Follows the topics of Effective Java, 3rd edition, by Joshua Bloch (Item 20: Prefer interfaces to abstract classes). Every explanation, example and line of code in this lecture is original. Previous lecture: L020 Java Inheritance Design: Never Call Overridable Methods in Constructors Next lecture: L022 Java Default Methods: How Adding One Broke Working Code (Java 21 getFirst) #Java #EffectiveJava #JavaInterview #SeniorJavaDeveloper #JavaBestPractices #EngineerX #JavaInterfaces #AbstractClass #DefaultMethods #EffectiveJava #JavaInterview