chapter eight

8 Building a rocket

 

This chapter covers

  • Building complex data structures made up of many different objects of different types
  • Abstracting away differences between different but related types

In our last chapter, we made some simple composite types to represent different types of warriors. However, in more realistic applications, you will have to combine many different types of objects into more complex data structures.

To explore this topic, we will be building a rocket in code. Why a rocket? Because rockets are made up of many different parts. That gives us an opportunity to build composite types out of other composite types and show different ways in which abstract types can be used in Julia to facilitate the construction of complex data structures.

This rocket example will be used to explore many other topics later in the book, such as how Julia represents collections of objects.

Our code example will start by defining a simple rocket Rocket consisting of a Payload, Tank and an Engine object. Later we will modify our simple type definition to create a more complex multi-staged rocket made up of multiple StagedRocket objects.

Next we will modify our code further to add a type Cluster representing a cluster of rocket engines which can be attached to any rocket stage.

At the end we will define a function launch! to simulate the launch of a multi-stage rocket.

8.1 Building a simple rocket

8.2 Maintaining invariants in your code

8.3 Making objects with constructor functions

8.4 Difference between outer and inner constructors

8.5 Modeling rocket engines and payloads

8.6 Assemble a simple rocket

8.7 Creating a rocket with multiple stages and engines

8.8 Launching a rocket into space

8.9 Summary