Week 14: Polymorphism & Object-Oriented Programming
🔗 Pre-Class Learning Material
- CppCon 2019: Jon Kalb “Back to Basics: Object-Oriented Programming”
- start at 4:42, watch until 28:30
- introduces object-oriented programming, discusses some design best practices
- rest of the talk discusses implementation best practices (reccommended!)
- Better Code: Runtime Polymorphism - Sean Parent
- start at 1:48, watch until 38:21
- discusses a solution for runtime polymorphism without an inheritance-based API
- middle part goes on a bit of a tangent about copy constructors and saving copies before presenting the complete solution, feel free to fast foward that part
- rest of the talk adds real-world context and discusses some additional features made straightforward to implement by using the runtime-concept idiom (reccomended!)
🔗 Conversation Starters/Discussion Questions
- What are the best examples of object-oriented or runtime-polymorphic you’ve used, maintained, and/or implemented? What made them great to work with?
- What are the worst examples of object-oriented or runtime-polymorphic you’ve used, maintained, and/or implemented? What made them not so great to work with?
- How do C++’s polymorphism toolkit/idioms compare to approaches to polymorphism in other languages (Rust? Python? etc.)?
- From the Sean Parent YouTube comments… (WON YOO)
I see global draw() function can be specifically defined with different types if I want to have a different behavior in the function other than a template function defines. Wouldn’t this pattern cause developers less convenient to find what methods can be overridden or not unlike the traditional polymorphism? For example, in traditional inheritance, if a method is virtual, I can know that can be overridden.
- Also from the Sean Parent YouTube comments… (Rob Inson)
How is it different from the pimpl idiom? …