This composition mechanism is used in this analysis modules package. There are many quantities (such as the norms of the symmetric and anti-symmetric part of the matrix) that can be computed together at practically the same cost as either one alone. Thus, when one is requested by calling ComputeQuantity(), the other one will be compute as well, and attached to the matrix object. A call to ComputeQuantity() for this second quantity will then just return the attached number, and not be computed separately.
The routine HasQuantity() can query which quantities are already attached.
As a result of the use of attached quantities, benchmarking the AnaMod modules is a bit tricky. You can forced computation of the requested quantities by calling PetscObjectIncreaseState() on the matrix object after each call to ComputeQuantity().