Run-time association of colleagues is performed using the AddColleague function, which is defined as follows:
void AddColleague(IPKIFColleague* m, bool transferOwnership = true);
The function takes a pointer to an IPKIFColleague object as the first parameter and an optional bool as the second parameter. The bool value indicates whether ownership of the colleague object is being transferred to the mediator for memory management purposes. Passing true for the second parameter will result in destruction of the colleague when the mediator is destroyed. Passing false for the second parameter permits a colleague to live longer than the associated mediator. When false is passed, the mediator receiving the colleague MUST be terminated (by a call to Terminate and/or destruction of the mediator) prior to destruction of the colleague.
Alternatively, colleague objects may be associated with mediator objects by requesting creation of mediator objects containing a default collection of colleague objects. The constructor for each mediator class takes a bool value that has a default value of false. When true is passed, a default collection of colleagues will be created and associated with the mediator instance when the Initialize function is invoked. The following code sample shows creation of a CPKIFPathProcessingMediator2 object containing the following default colleague objects: IPKIFPathBuild, IPKIFPathValidate, and IPKIFPathBuildAndValidate.
//create instance passing true as constructor parameter
CPKIFPathProcessingMediator2* pathMediator = new CPKIFPathProcessingMediator2(true);
//invoke initialize to cause creation of default colleague objects
pathMediator->Intialize();
//use the object