The parent-child relationship is a foundational concept of object oriented design. There are three kinds of object relationships in the UML specification:
Aggregation is the parent-child (also named whole-part) relationship. It is implemented in PostSharp by the AggregatableAttribute aspect described in Walkthrough: Annotating an Object Model for Parent-Child Relationships.
Composition is an aggregation relationship where the parent controls the lifetime their children. It is implemented in PostSharp by the DisposableAttribute aspect pattern, which relies on the AggregatableAttribute aspect. For details, see Walkthrough: Automatically Disposing Children Objects.
Association is a simple reference between two objects.
Despite its importance, C# and VB have no keyword to represent aggregation. All C# and VB object references correspond to an association. Therefore, most applications and frameworks tend to re-implement the aggregation relationship, resulting in boilerplate code and defects. For instance, UI frameworks such as WinForms and WPF rely on a parent-child structure.
The Aggregatable pattern is used by other PostSharp aspects, including all threading models (ThreadAwareAttribute), DisposableAttribute and RecordableAttribute. You can also use the aspect to automatically implement a parent-child relationship in your own code.
This section shows how to prepare a class so that it can participate in a parent-child relationship.
This section describes how to enumerate the children of an object thanks to the visitor pattern.
This section shows how to automatically implement the IDisposable interface so that children objects are disposed when the parent object is disposed.
This section describes how to annotate aggregatable object models programatically.
This section covers advanced topics related to collections in aggregatable object models.
This section descirbes usage of immutable collections in aggregatable object models.