Monthly Archives: January 2010

Kata2: The Decorator Pattern

 

This the second part of the series of Coding Kata’s. Here we’ll explore the Decorator pattern.

This is the user story:

You need to send alerts to your customers when a new product is available. 
An Alert is represented by the Alert Class:

public class Alert
{
      public String DestinationAddress { get; set; }
      public String SenderAddress { get; set; }
      public String Content { get; set; }
      public string Log { get; set; }
}

Classes used to send the Alerts implement the following interface:

public interface ISender
{
        void Send(Alert alert);
}

 

  • Create an Alerter class that send the appropriate alerts.  
  • Alerts are always send by e-mail.
  • Customers can also subscribe to receive alerts via sms and/or through messenger. 
  • Use the Decorator pattern to configure the Alerter

    You do not need to use real infrastructure code to send the alert, just append a string that contains the Sender through which the message was send.
    ->Append the following text to the Alert.Log when the message is send by:

  • e-mail      : “Message was send by e-mail”
  • sms         : “Message was send by sms”
  • messenger: “Message was send by messenger”

 

Show Solution

 

Coding Kata on design patterns: Kata1, The Abstract Factory Pattern

 

This post is the first in a series dedicated to Coding Kata’s and design patterns.  

Because I’m not always able to remember all the patterns I decided to learn by practice.  

Every week I will try to create a Kata with a simple problem that has to be resolved with one of the Gov’s design patterns.  

Because I want to start smoothly we’ll start with one of the simplest pattern -> the Abstract Factory.

Kata1 ->

A product has a property Name.  

Because the Name is used as an identifier it can’t be changed.  

We need to be able to construct 2 products with following names: Product1, Product2.

Use the abstract factory pattern so that you’re able to create Products.

 

This is my solution for Kata1.