[Insight-developers] Modes versus Objects

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Thu Jun 2 12:40:53 EDT 2011


Le 2 juin 11 à 17:32, Bill Lorensen a écrit :

> Folks,
>
> This discussion is motivated by recent activity...
>
> Back in the early days of OO programming, I recall having discussions
> about the use of modes versus objects. When I taught OO courses I
> always discouraged modes if they changed the "identity" of the object.
>
> Should a mode be used to change the behaviour of an object or should a
> new object be created?
>
> A case where a mode is better than an object:
> Controlling the visibility of an actor in VTK:
>  1) Mode: vtkActor VisibilityOn/Off
> or
>  2) Object: two classes vtkActor and vtkVisibleActor
>
>  1) is the appropriate solution since, at run time, an application
> may want to change the visibility of an actor.
>
> A case where an object may be better than a mode:
>  1) Mode: itkShiftScaleImageFilter
> SetOperationOrderToShiftScale()/SetOperationOrderToScaleShift()
> or
>  2) Object: two classes itkShiftScaleImageFilter and  
> itkScaleShiftImageFilter
>
> A VTK approach versus an ITK approach
>  1) mode: vtkImageMathematics 21 different modes  
> (ADD,SUBTRACT,MULTIPLY,...)
>  2) object: itkAddImageFilter, itkSubtractImageFilter,
> itkMultipleImageFilter...
>
> It is not always obvious as to the best choice. But, I think the
> question should be asked anytimne we introduce a new "mode".
>

Hi Bill,

This is certainly a good thing to keep in mind while adding a new  
feature, and your example on ShiftScaleImageFilter and  
ScaleShiftImageFilter certainly make sense.

But I'm not sure the decision will be that easy when it comes to base  
classes.
Adding features in base classes may help to avoid duplicating the  
subclasses, and code duplication is certainly something we want to  
avoid.

The BinaryFunctorImageFilter recently modified is a good example - do  
we want to have two versions of Add image filter, one for indexed data  
access and another for physical space data access?

The InPlaceImageFilter is another good example. It allows a subclass  
to run in place or not. We probably don't want to duplicate the  
subclasses to implement that feature.

It would be nice if everything can be simple!

Gaëtan


-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr  http://www.itk.org
http://www.mandriva.org  http://www.bepo.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110602/1eca3800/attachment.pgp>


More information about the Insight-developers mailing list