Core · Module 6 · Lesson 4 of 6
Abstract Classes and Pure Interfaces
Separate shared state from pure contracts with abstract bases and pure interfaces, and enforce implementation in derived types through pure virtual functions.
Pro — members onlyAbout 11 minutes
By the end you can
- Explain how a pure virtual function makes a type abstract
- Contrast an abstract class with a pure interface
- Implement a derived type that fulfills a base contract
01 · A question first
A catalog printer needs a title and loan period from every item, while a logger needs message and error output from any sink. How do you force every future item and every future logger to supply those operations, while still sharing color or identifier state in one place?
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with two contracts
- How abstract types work
- Why the split is correct
- Cost and design tradeoffs
- Mistakes and variations
- Analogy and a narrow contract check
- Where this is used
03 · Practice
Something wrong with this lesson? Report a problem