Moon Landing using Inheritance

1 Body

In the MoonLanding example from Chapter 3 the declaration of certain fields like mass and name were repeated in each of the classes CelestialBody and Rocket. This can be avoided by collecting those field declarations into a generic body class called Body, and reusing these by inheriting Body into CelestialBody and Rocket.

We have replaced the general keyword
class by the restricted class keyword model which has the same semantics as class apart from the fact that it cannot be used in connections. The reason is that it is more common practice to use the keyword model for modeling purposes than to use the keyword class.



2 Celestial Body


3 Rocket


4 Moon Landing


5 Moonlanding Simulation




Diagram 1: Altitude of the Apollo rocket over the lunar surface




Diagram 2: Thrust from the rocket motor, with an initial high thrust f1 followed by a lower thrust f2.




Diagram 3: Rocket mass decreases when the fuel is consumed




Diagram 4: Gradually increasing gravity when the rocket approaches the lunar surface




Diagram 5: Vertical velocity relative to the lunar surface