A construction pattern for dependent objects

Sometimes in a graph the dependent objects need to be registered with a parent once they are constructed.

This relationship may not be obvious to the designer. Resulting in doing things like the following


Parent
{
    create a child
    register the child
}

Parent
{
   create a child
}

Child
{
   constructor(parent)
   {
      //do your own construction

      //then register the child
      parent.register(this);
   }
}

child 
{
  //No explicit pointer required for the parent
  //So it is easy to forget not to take the parent 
  //as a constructor
}