# Member visibility when writing new VTK classes

**URL:** <https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208>\
**Category:** Development\
**Created:** [August 28, 2023, 2:42pm UTC](https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208 "2023-08-28T14:42:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [August 28, 2023, 2:42pm UTC](https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208/1 "2023-08-28T14:42:54Z")

</div>

As VTK tries to be as retrocompatible as possible with extensive deprecation mechanism, VTK developers often struggle with the amount of work needed to cleanly deprecate protected members (non-virtual methods and variables).

Indeed a protected members is perfectly accessible from a derived class, and VTK users have been deriving VTK class **in their own apps** for as long as VTK existed.

In order to remove a variable, change a name, change a method API, one need to cleanly deprecate it in order **to be sure** not to break someone else application.

The amount of work it represent can sometimes be overwhelming which means that sometimes, deprecation doesn’t happen, or the change that would be cleaner is not done to avoid deprecation.

A simple fix for that is to consider that members and non-virtual method should by default be put into `private` visibility, while only what should be considered the actual API of the class be put into `public` and `protected` visibility depending on the intent.

If will also make sure that setters and getters are correctly being defined and used in VTK, instead of accessing the members directly, which will improve our API.

Of course, all the existing code will not be moved, but new code should try to follow that and any rework of a class may want to deprecate protected members into private members if possible.

This is a suggestion, please let me know if you have any inputs on this.

Note: This is unrelated to the pimpl, which should already contain all internal member of the class.

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [August 28, 2023, 2:44pm UTC](https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208/2 "2023-08-28T14:44:28Z")

</div>

Example, this should be avoided:

```auto
vtkMyClass
{
  protected:
    int myMember;
}

```

This should be prefered:

```auto
vtkMyClass
{
  public:
    vtkGetMacro(int, myMember);
    vtkSetMacro(int, myMember);

  private:
    int myMember;
}

```

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [September 4, 2023, 7:54am UTC](https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208/3 "2023-09-04T07:54:29Z")

</div>

Split this topic on September 4, 2023, 7:54am UTC

6 posts were split to a new topic: [About avoiding public virtual method in VTK](https://discourse.vtk.org/t/about-avoiding-public-virtual-method-in-vtk/12240)

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [September 4, 2023, 10:07am UTC](https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208/9 "2023-09-04T10:07:43Z")

</div>

Without any negative feedback, I will add that recommendation in the guide.

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [September 4, 2023, 10:19am UTC](https://discourse.vtk.org/t/member-visibility-when-writing-new-vtk-classes/12208/10 "2023-09-04T10:19:35Z")

</div>

[https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/10473](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10473)
