Object Model Hierarchies

The fact that one object’s properties and methods can return another object, thus creating the concept of child objects, is of paramount importance, for it adds a very useful structure to the object model.

It seems by looking at the literature that there is not total agreement on when one object is considered a child of another object. For our purposes, if object A has a property or method that returns object B, then we will consider object B a child of object A and object A a parent of object B.

For example, the Range object, which represents a contiguous area within a document, has a Font property, which returns a Font object. Hence Font is a child of Range and Range is a parent of Font. The Font object is also a child of the Selection object, which represents the current selection in a document window. In fact, an object can have many parents and many children.

It is worth elaborating on my choice of definition for child objects. I could take a more restrictive view by requiring that the object property or method actually have the same name as the child object. For instance, the Application object has a Documents property that returns the Documents collection. Hence Documents is a child of Application. However, this definition is too restrictive. For instance, the only property or method of the Application object that returns a Dictionaries collection object is the CustomDictionary property. Hence the Dictionaries object would not be considered a child of ...

Get Writing Word Macros, Second 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.