10.5 Designing and Implementing a Solar System
Now we are ready to build our solar system, which will consist of a sun and a collection of planets, with each planet defined to be some distance away from the sun. We will assume that the sun resides at the center of the solar system. We will implement the SolarSystem class in the same way that we have implemented the other classes seen so far: by providing a constructor that will be responsible for defining the instance variables and by defining appropriate accessor and mutator methods.
The complete SolarSystem class is shown in Listing 10.8. Our constructor (lines 2–4) assumes that a basic SolarSystem object must have a Sun object at its center and a list of planets. As a consequence, the constructor ...
Get Python Programming in Context, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.