   Best way to do this? (OOP, Trees)
  Hello folks, yet another design principles question:Let's say, I have a class which is a graphical representation of some data modelclass MyDataModel : SomeTreeModel{ <...>}class MyDataModelGraphicalRepresentation : SomeSceneGraphNodeClass{MyDataModel* theDataModel;void GenerateGraphicalRepresentationFromDataModel(){  buildRepresentation(theDataModel);}}The graphical representation keeps a reference theDataModel to the data to construct the geometry from. The data model itself is tree-based. The MyDataModelGraphicalRepresentation class is some scene graph library node class extension.My question is, in what way you should store the reference to the data model. For now, I can think of 3 options:1) Store a pointer to the data model. Have it allocated and deallocated outside the MyDataModelGraphicalRepresentation class object and pass the pointer.class MyDataModelGraphicalRepresentation{MyDataModel* theDataModel;void SetDataModel(MyDataModel* dataModel){    this->theDataModel = dataModel;}void GenerateGraphicalRepresentationFromDataModel(){if(this->theDataModel)  buildRepresentation(this->theDataModel);}}2) Store a pointer to the data model. Have it allocated and deallocated INSIDE the MyDataModelGraphicalRepresentation class object and pass the pointer.class MyDataModelGraphicalRepresentation{MyDataModel* theDataModel;MyDataModelGraphicalRepresentation(){    theDataModel = new MyDataModel();} MyDataModelGraphicalRepresentation(){    delete(theDataModel);}void GenerateGraphicalRepresentationFromDataModel(){if(this->theDataModel)  buildRepresentation(this->theDataModel);}}3) Store the tree as an automatic variable. If you want to set the tree data, a deep copy of the tree is done.class MyDataModelGraphicalRepresentation{MyDataModel theDataModel;void SetDataModel(MyDataModel& newDataModel){MyDataModel.setDeepCopy(newDataModel);}void GenerateGraphicalRepresentationFromDataModel(){    buildRepresentation(this->theDataModel);}}What do you think?   
  It all depends on the ownership model you want to use.If you want to "tack on" your object on top of an existing data set which always has a longer lifetime than your object, then using a reference to the object (without any ownership semantics) will work.If you want your object to manipulate a data set independently of the original data set, then some exclusive ownership scheme (for instance, aggregation) with initialization by copy is better.If you want shared ownership of the manipulated data, use an adapted pointer type, such as boost::shared_ptr.