[Insight-developers] Compile-time decorator pattern

Bradley Lowekamp blowekamp at mail.nih.gov
Fri Jan 7 13:42:46 EST 2011


Hello,

I have just push a little branch which shows the basis for a potentially very useful design pattern for ITK filters:

http://review.source.kitware.com/#change,684

I could not find an official name for this patterns, I have read about it before and used it in a few places as well in other projects. I decided to call it "compile-time decorator" because it's design to add features to a multiple class hierarchies.

The motivation is to be able add reuse functionality, without changing exiting hierarchy structures. This an alternative to multiple inheritance in for some situations. 


The implementation of the pattern is to have the parent of a class be a template argument to the class.

template< class TInputImage, class TOutputImage = TInputImage, 
                   class TParentImageFilter = ImageToImageFilter< TInputImage, TOutputImage > >
class ITK_EXPORT InPlaceImageFilter:
    public TParentImageFilter
{...}

For example say I have a good inplace algorithm for WhiteTopHatImageFilter:
http://www.itk.org/Doxygen/html/classitk_1_1WhiteTopHatImageFilter.html

However, it's already embedded in an existing complex hierarchy, so I can not re-organize the class to be derived from InPlaceFilter. However, it's is good practice to reuse the existing code in the InPlace filter. This can be over come with this pattern by declaring the class in the following fashion.
			
template< class TInputImage, class TOuputImage, class TKernel >
class ITK_EXPORT WhiteTopHatImageFilter:
	public InPlaceImageFilter<TInputImageFilter, TOutputImageFilter, KernelImageFilter< TInputImage, TOutputImage, TKernel > >
{...}


This may be a useful design pattern for GPU implementations of filters, along with adding certain streaming functionality to sinc like filters.

Brad

========================================================
Bradley Lowekamp  
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110107/b2077ca3/attachment.htm>


More information about the Insight-developers mailing list