Checkpoint: The Code So Far (After LSP)

Everything covered through the Liskov Substitution Principle: Flyable and Eater interfaces replacing the broken FlyingBird/NotFlyingBird class split.

September 14, 202610 min read12 / 20

This is a running snapshot, not a new lesson. It's everything the bird hierarchy looks like after the previous posts: a penguin that can't fly, and a sparrow that can't eat, both handled correctly.

Interfaces mark behavior. Classes mark identity. That split is what makes this work.

main.cpp
#include <vector> #include "bird/classes/Bird.h" #include "bird/interfaces/Flyable.h" #include "bird/classes/Crow.h" #include "bird/classes/Sparrow.h" #include "bird/classes/Owl.h" #include "bird/classes/Pigeon.h" #include "bird/classes/Penguin.h" int main() { Crow crow("Crow", "black", 2); Sparrow sparrow("Sparrow", "brown", 1); Owl owl("Owl", "brown", 3); Pigeon pigeon("Pigeon", "grey", 2); Penguin penguin("Penguin", "black-and-white", 4); std::vector<Bird*> allBirds = { &crow, &sparrow, &owl, &pigeon, &penguin }; for (Bird* bird : allBirds) { bird->walk(); } std::vector<Flyable*> fliers = { &crow, &sparrow, &owl, &pigeon }; for (Flyable* bird : fliers) { bird->fly(); } crow.eat(); pigeon.eat(); return 0; }