Chapter 7. Object orientation, Groovy style

 

This chapter covers

  • Defining classes and scripts
  • Object-oriented features: inheritance, interfaces, multimethods, and traits
  • Working with GroovyBeans
  • Advanced syntax features: GPath, spread operators, and command chains

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius—and a lot of courage—to move in the opposite direction.

Albert Einstein

There’s a common misconception about scripting languages. Because a scripting language might support a less rigid approach to typing and provide some initially surprising syntax shorthands, it may be perceived as a nice new toy for hackers rather than a language suitable for serious OOP. This reputation stems from the time when scripting was done in terms of shell scripts or early versions of Perl, where the lack of encapsulation and other object-oriented features sometimes led to poor code management, frequent code duplication, and obscure hidden bugs. It wasn’t helped by languages that combined notations from several existing sources as part of their heritage.

Over time, the scripting landscape has changed dramatically. Perl has added support for object orientation, Python has extended its object-oriented support, and, more recently, even JavaScript can be generated from more strictly typed languages like TypeScript and PureScript.

7.1. Defining classes and scripts

7.2. Organizing classes and scripts

7.3. Advanced object-oriented features

7.4. Working with GroovyBeans

7.5. Using advanced syntax features

7.6. Summary

sitemap