explain the vtk architecture design

Why is the idiom to use this pattern. vtkSmartPointer<vtkObject> MyObject = vtkSmartPointer<vtkObject>::New();

Quick note about recent VTK : For most case, uses vtkNew<vtkMyObject> myObject instead.

Why in most classes the constructor set to private or public?

All vtkObject derived classes have protected constructor and destructor, and private copy operator.

Its apparent this approach was a design choice, but I would like to know more about why, and what are other approaches out there?

Quick answer : to make sure that object creation and destruction can be tracked, which is
practical in a number of ways, which includes but is not limited to, factories (creating another object than the one that have been requested), leaks detection.

how would those design choices change with modern c++ or would they ?

SmartPointer could almost be reimplemented with shared_ptr. This may happen.

1 Like