Chapter 20. Using object hierarchies for complex output

 

Way back in chapter 7, we showed you how to create custom objects to use as the output of your functions. To this point, the objects you’ve created have essentially been flat, meaning they could be easily represented in a flat data file structure such as a CSV file or in an Excel spreadsheet or in a simple table. That’s because your objects, to this point, have represented only a single entity, such as a computer system. In this chapter, we’re going to show you how to work with more complex objects that include multiple entities in a single, hierarchical object.

20.1. When a hierarchy might be necessary

Typically, a single object should represent one single kind of thing. That might be a computer system, a disk drive, a user, or a file. The properties of those objects should directly relate to the entity that the object represents. For example, if you’re creating an object to represent a computer system, then it might have properties such as these:

  • Computer name
  • Operating system version
  • BIOS serial number
  • Manufacturer name

20.2. Hierarchies and CSV: not a good idea

20.3. Creating nested objects

20.4. Working with nested objects

20.5. Lab