Interface vs abstract class 00:00:00 Make a prediction You will decide when callers need a promise and when related implementations also benefit from a shared recipe. A PDF exporter cannot use a text exporter's character-escaping code. Does it still belong behind the same invoice export interface? Yes, if both turn an invoice into export bytes under the same contract. It need not inherit text-only state or a recipe that cannot apply to PDF. 00:00:28 Wagons and badges Freight wagons can all carry the railway operator's coupling badge. Two refrigerated wagons may also share a cooling chassis. A flatbed can earn the coupling badge without inheriting a cooling system. An interface describes a capability a caller can rely on. An abstract class can additionally share state and an implementation among a compatible family. An interface is a named promise: a list of operations and what they mean. A class that implements it takes on the promise. The interface holds no data of the object, has no constructor, and says nothing about how the work is done. It describes what something can do. Callers should depend on as little as possible. A method that takes a Flyable accepts a plane, a drone and the fake in a test. A method that takes a Vehicle accepts only things with that parent. 00:01:20 Separate a promise from a shared recipe A caller needs every exporter to accept an invoice and return bytes. An interface states that promise and lets unrelated implementations participate. A CSV exporter can implement it directly. A family of text exporters might separately share a base class for escaping and encoding. Keep the caller typed against the promise. A PDF exporter with a different implementation does not need to inherit text-specific state. Write a test that supplies the same invoice to the export API and checks for a readable result. A PDF exporter and a CSV exporter need different internals. Neither needs to inherit a shared mutable buffer just to promise the same operation. 00:02:07 Share only what really is common Several games need a start, play and finish sequence. An abstract base can enforce the sequence and leave play as an overridable step. A scoreboard that only needs the final score should instead depend on a tiny score provider interface; it gains nothing by inheriting the game loop. Now give the game templates a rule: finish must always follow play, even if the scoring algorithm changes. The base can own that sequence and delegate the middle step. A scoreboard that only consumes results gains nothing by inheriting the whole game lifecycle. Adding a compulsory abstract method to a public interface can break clients that implement it. An honest default is useful only when it really preserves the original promises. A caller needing only a score can use a tiny score-reader contract even if the games themselves share an abstract base. Java List, AbstractList, ArrayList. The documentation calls AbstractList a skeletal implementation of the List interface that minimizes the effort to implement it. Callers hold List. Java Comparable, Iterable, AutoCloseable. Three promises that unrelated classes make: can be ordered, can be looped over, can be closed by try-with-resources. 00:03:30 Try an interview follow-up Two interfaces have the same default method. What happens? If one interface extends the other, the more specific wins. A method inherited from a class wins over both. Otherwise it does not compile until my class overrides the method. The override may explicitly delegate to the implementation on one named parent interface. Two unrelated libraries can export a report. Start with the operation both callers need. Now suppose your own exporters all open a temporary file and must clean it up in the same order. An interface can describe exporting. A shared base implementation can provide that lifecycle for the exporters you control. 00:04:15 What to take with you Interface: a promise, can-do, as many as you like, no state. Abstract class: a half built object, is-a, one parent in most languages, with state, constructor and code. Start with the interface that the caller needs. Add an abstract class when two or more implementers really share state or a fixed sequence of steps. Keep the interface as the type of variables and parameters.