[Insight-users] Why classes attributes should be private in ITK?

Luis Ibanez luis.ibanez at kitware.com
Wed, 14 Apr 2004 12:28:35 -0400


Hi Yann,

Mmm, You should actually we wondering why
there shoule be *any* public or protected
variables in ITK classes...

Encapsulation is a fundamental principle in
Object Oriented programming. Every variable
must be private until you prove that the design
requires otherwise.

Note that for getting access to the variables
most ITK classes offer Set() / Get() methods
that are constructed with the itkSetMacro and
itkGetMacro.

Your derived classes should simply use these
Get/Set methods for getting access to such
variables.

If you indicate what classes in ITK are giving
you trouble, and what kind of variation of the
filters you want to implement, we will be happy
to add the Set/Get methods needed for your class
to work correctly. That's the beauty of Open
Source and Exterme Programming    :-)


Please let us know,


    Thanks


      Luis



------------------
Lemeur Yann wrote:

> Hi everybody!
> 
> I've used ITK for about a month and I wonder why almost all classes variables are private. 
> Actually, I have a problem when I want to create a class (class B) which inherit from a mother-class (called class A) in order to change one method (in my case: adding some lines of code to GenerateData() ).
> If this method needs to access to class variables which are private (defined in class A), I can't reimplement it in my new class B because variables are private in the mother class A.
> I also can't redefine the variables of A with the same name in B! 
> 
> The only solution I've found is to write a "sister class" which inherit from the same class as A, and which is the same as A excepted the few changes I want to add.
> Does somebody know another solution to make it properly (ie to avoid to rewrite classes which don't change!)
> And I also wonder what is the interest to declare all the class variables private?
> 
> Thanks!
> Yann   
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>