Skip to content

Instantly share code, notes, and snippets.

@trailmax
Created April 4, 2019 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trailmax/bbf9180a1da64d0ac823350ed99b1d9d to your computer and use it in GitHub Desktop.
Save trailmax/bbf9180a1da64d0ac823350ed99b1d9d to your computer and use it in GitHub Desktop.
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