Click here to Skip to main content
15,897,371 members
Articles / Programming Languages / C#

"Please Don’t Fail Me!" - Decorator Cries Out to Template Method

,
Rate me:
Please Sign up or sign in to vote.
4.68/5 (13 votes)
13 Sep 2009CPOL6 min read 55.5K   145   20  
Are your classes that implement the Template Method Design Pattern "Decorator aware"?
using System;
using HypotheticalShapeLib;

namespace Decorators
{
   public class ShapeFiller : ShapeDecoratorBase
   {
      public ShapeFiller(Shape shape)
         : base(shape)
      {
      }

      protected override void Paint()
      {
         // Draw the Shape First
         base.Paint();

         Console.WriteLine(string.Format("Filling Shape - {0}", _shape.TypeName));
      }
   }

   public class ShapeBorderThickener : ShapeDecoratorBase
   {
      public ShapeBorderThickener(Shape shape)
         : base(shape)
      {
      }

      protected override void Paint()
      {
         // Draw the Shape First
         base.Paint();

         Console.WriteLine(string.Format("Thickening border of Shape - {0}", _shape.TypeName));
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Technical Lead HCL Technologies LTD
India India
I am Sanjeev Venkat working for HCL Technologies since 2003. I've 9 years of experience in Software Development. My core expertise include Windows Device Drivers, COM, C++, .NET.

Comments and Discussions