Created
April 4, 2019 10:37
-
-
Save trailmax/bbf9180a1da64d0ac823350ed99b1d9d to your computer and use it in GitHub Desktop.
Decorator Kata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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