Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Decorator Kata
using System;
namespace DecoratorKata
{
class Program
{
static void Main(string[] args)
{
var service = new RoundBracketsDecorator(
new SquareBracketsDecorator(
new RoundBracketsDecorator(new ConcreteImplementation()
)));
Console.WriteLine(service.GiveMeData());
Console.ReadLine();
}
}
public interface IService
{
string GiveMeData();
}
public class ConcreteImplementation : IService
{
public string GiveMeData()
{
return "Hello world";
}
}
public class RoundBracketsDecorator : IService
{
private readonly IService decorated;
public RoundBracketsDecorator(IService decorated)
{
this.decorated = decorated;
}
public string GiveMeData()
{
return "(" + decorated.GiveMeData() + ")";
}
}
public class SquareBracketsDecorator : IService
{
private readonly IService decorated;
public SquareBracketsDecorator(IService decorated)
{
this.decorated = decorated;
}
public string GiveMeData()
{
return "[" + decorated.GiveMeData() + "]";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.