- Learn Scala Programming
- Slava Schmidt
- 179字
- 2021-06-10 19:35:50
Object-oriented aspects of functions
We mentioned that Scala is a fusion of object-oriented and functional paradigms. Because of this, Scala has functions as a first-class element of the language. Also because of this, everything is an object in Scala. This is partly related to the fact that everything is an object or a primitive type in the JVM, but Scala goes further and also hides primitives behind objects.
It turns out that functions are also objects! Depending on the number of arguments, they extend one of the special traits. Also because of their object-oriented nature, it is possible to implement additional features by defining additional methods on the implementing class. This is how partial function is implemented. It is also natural to utilize companion objects to define common logic for functions so that it can be easily reused. It's even possible to write some custom implementation of a function, though it is seldom a good idea.
Each of these aspects is worth a deep dive, but to really understand them, we need to start with some implementation details.
- 從零構建知識圖譜:技術、方法與案例
- JavaScript全程指南
- Spring Cloud Alibaba微服務架構設計與開發實戰
- Vue.js前端開發基礎與項目實戰
- Java加密與解密的藝術(第2版)
- 算法精粹:經典計算機科學問題的Python實現
- Practical DevOps
- Full-Stack React Projects
- Python貝葉斯分析(第2版)
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- Mastering ArcGIS Enterprise Administration
- Python Data Science Cookbook
- JSP程序設計實例教程(第2版)
- Mastering AWS Security
- Python函數式編程(第2版)