Lesson 10. Capstone: Functional object-oriented programming with robots!
This capstone covers
- Using functional programming to create objects
- Creating example objects that interact with each other
- Representing state in a functional way
A common misconception is that object-oriented programming (OOP) and functional programming somehow stand in opposition. In reality, this couldn’t be further from the truth. Many functional programming languages support some form of object-oriented programming, including Common Lisp, R, F#, OCaml, and Scala. In this unit, you explored the idea that functions can be used to perform any computation. So it makes perfect sense that by using the tools of functional programming, you can create a basic object-oriented programming system!
This is your first capstone exercise. In this exercise, you’ll see how to use the tools of functional programming to replicate common design features found in OOP languages. You’ll build a simple cup object and then move on to modeling fighting robots!
Think like a programmer
Haskell doesn’t use objects, so why on earth should you spend time implementing OOP from scratch? The main reason is it allows you to understand the power of the functional tools you’ve been learning about so far. If you can understand how to build OOP by using closures, lambdas, and first-class functions, you’ve truly reached functional enlightenment.