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 the last chapter, you 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, you will be building a rocket in code. Why a rocket? Because rockets are made up of many different parts. That gives you 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.

The code example will start by defining a simple rocket of type Rocket, consisting of a Payload, a Tank, and an Engine object. Later you will modify the simple type definition to create a more complex multistage rocket made up of multiple StagedRocket objects. Next you will modify the code further to add a type Cluster, representing a cluster of rocket engines, which can be attached to any rocket stage. At the end you will define the function launch! to simulate the launch of a multistage rocket.

8.1 Building a simple rocket

8.2 Maintaining invariants in your code

8.3 Making objects with constructor functions

8.4 Differences between outer and inner constructors

8.5 Modeling rocket engines and payloads

8.6 Assembling a simple rocket

8.7 Creating a rocket with multiple stages and engines

8.8 Launching a rocket into space

Summary