86. Introduction
Now that you have a handle on constructing classes we’ll explore the various Groovy constructs for creating a more extensible codebase:
- Interfaces: define a set of method signatures that are then implemented by a class (or classes).
- Traits: add abilities to a class
- Inheritance: Allows a class to inherit the functionality of another class and extend it.
- When
ChildClassinherits fromParentClass, we say thatChildClassis a subclass ofParentClassand thatParentClassis a superclass ofChildClass1.
- When
First up, we’ll look at how to organise your code before those classes get out of hand.
The Shapes demo
Throughout this section I’ll build up an example library for working with two-dimensional shapes. You’ll see this in chapters with the The shapes demo prefix and a full listing is available as an appendix.
As the Shapes demo source code is laid out as a larger project and divided into packages, you won’t be able to run it
via groovyConsole.
To support you in trying out the demo I’ve setup the shapes demo
mini site. This provides a number of handy resources:
- A guide to building (compiling) the code both directly using
groovycand with the Gradle build tool. - Links to download the code
- Various reports on the code
Once you’ve read through the chapters in this section, head to the shapes demo mini site and give it a try.