Polymorphism with Protocols
summary
Shows a concrete Swift refactor: a messy class-based expression tree with optionals becomes protocols + structs so nodes are value types, eliminating shared mutable state. Implements a tree evaluator (prints 10 for 23+4, 100 after adding a power node) and a simple UIImage renderer via protocol extensions* and draw helpers. Uses Xcode Playground, Swift stdlib pow, and protocol requirements for evaluate(); the refactor reduces conditionals, makes unit testing easier, and preserves runtime polymorphism via protocol conformance.
AI-written summary · about
chapters (8)
- 0:00Start
- 0:46Need for a Good Api Design
- 1:35Three Characteristics of Good Api Design
- 2:05What Kind of Data Structure Can We Use To Express a Mathematical Formula
- 2:39First Naive Approach
- 6:01Evaluate Function
- 7:20Abstract Class
- 19:58String Interpolation








