[Insight-developers] When are variables made private vs protected?

Cory Quammen cquammen at cs.unc.edu
Fri Dec 2 14:08:53 EST 2011


I think the answer is to default to private and use protected only
when you have to.

In your use case, the setter and getter are inherited, so why would
you need to create those in your subclass? Also, you can access the
variable value from within your subclass with the superclass's getter.
Setting is a bit more problematic, because you may change the object's
modified time from within the class, but I think it would be rare to
set a value from within a subclass.

Cory

On Fri, Dec 2, 2011 at 2:00 PM, David Doria <daviddoria at gmail.com> wrote:
> I am curious how the decision to make member variables private vs
> protected is made. For example, I was trying to derive from
> itkMedianImageFunction and I noticed that the member:
>
> unsigned int m_NeighborhoodRadius;
>
> is private. Therefore, in my subclass, I have to create a new
> member+accessor+mutator for the same purpose. Why would all members in
> ITK not be protected so that they can be more easily subclassed?
>
> Thanks,
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>



-- 
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill


More information about the Insight-developers mailing list