polymorphism ruby
TRANSCRIPT
![Page 1: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/1.jpg)
Replacing Conditionals With
Polymorphism@gpespn
![Page 2: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/2.jpg)
“Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.”
-- Martin Fowler
@gpespn
![Page 3: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/3.jpg)
@gpespn
But why? • Easier to read • Maintainability • Extensibility • Isolation of change • Easier to test
![Page 4: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/4.jpg)
@gpespn
B+
![Page 5: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/5.jpg)
@gpespn
C-
![Page 6: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/6.jpg)
@gpespn
New Feature! Guest sessions
![Page 7: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/7.jpg)
@gpespn
![Page 8: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/8.jpg)
@gpespn
F-
![Page 9: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/9.jpg)
@gpespn
I just want to send a message
to an object
![Page 10: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/10.jpg)
@gpespn
-Woof!
-Meow!
![Page 11: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/11.jpg)
@gpespn
Polymorphism
tell don't ask
![Page 12: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/12.jpg)
@gpespn
![Page 13: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/13.jpg)
@gpespn
![Page 14: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/14.jpg)
@gpespn
![Page 15: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/15.jpg)
@gpespn
still have conditional!
![Page 16: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/16.jpg)
@gpespn
Create a high level abstract
class
![Page 17: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/17.jpg)
@gpespn
![Page 18: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/18.jpg)
@gpespn
Abstract Subclass Subclass
![Page 19: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/19.jpg)
@gpespn
Polymorphism
![Page 20: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/20.jpg)
@gpespn
![Page 21: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/21.jpg)
@gpespn
Whats the catch? • Parallel interfaces • Design patterns that are confusing to those unfamiliar to them
• New words/vocabulary into application. LOC went up! • Increased big picture complexity in exchange for macro clarity
• Too many Objects
![Page 22: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/22.jpg)
@gpespn
![Page 23: Polymorphism ruby](https://reader031.vdocuments.mx/reader031/viewer/2022021922/58eddb991a28ab71168b46a9/html5/thumbnails/23.jpg)
@gpespn
Questions?