using System; namespace decorator { abstract class Sentence { public abstract string GetText(); } class BasicSentence : Sentence { private string text; public BasicSentence(string s) { this.text = s; } public override string GetText() { return this.text; } } class CapitalisedSentence : Sentence { private Sentence sentence; public CapitalisedSentence(Sentence s) { sentence = s; } public override string GetText() { return sentence.GetText().ToUpper(); } } class SubSentence : Sentence { private Sentence sentence; private int startIndex; private int length; public SubSentence(Sentence s, int start, int len) { sentence = s; startIndex = start; length = len; } public override string GetText() { return sentence.GetText().Substring(startIndex, length); } } class Program { static void Main(string[] args) { Sentence s1 = new BasicSentence("Hello, World!"); Sentence s2 = new CapitalisedSentence(s1); Sentence s3 = new SubSentence(s2, 7, 5); Console.WriteLine(s1.GetText()); Console.WriteLine(s2.GetText()); Console.WriteLine(s3.GetText()); } } }