Understanding Reflection

Reflection draws a distinction between the base level of the program that doesn't change and a meta level that does change. The base level implements the application logic and makes use of information from the meta level. The meta level encapsulates the internal parts of the application that can change in meta objects. The meta level's data (the metadata) describes an application's attributes and behavior that can change.

The base level of the application interprets the metadata at runtime to adapt the application and include its new structural behavior. To get a complete view of the application, you must look at both the base-level objects and the current configuration of the meta objects.

Figure 16-1 shows two display instances created with identical base-level objects and different metadata. In this figure, the metadata is expressed with Extensible Markup Language (XML), but XML isn't the only way to represent metadata. The metadata describes the shape of objects by using only points and connections between points. The base level understands, and uses, two structural aspects of the application to create the desired objects. There are no specific predefined classes that take precisely three or four points; the base-level objects create new classes with as many points and lines as defined in the metadata. Arguably, this simplistic example could be done without reflection; what makes it reflection is that the internal representations of the objects are ...

Get Pattern-Oriented Software Architecture For Dummies 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.